2012-12-21 2 views
1

J'essaie d'obtenir mes commandes afin que j'affiche un contrôle qui a un bouton et une image qui occupe l'espace restant. Je cherchais à l'aide de poids, je peux l'obtenir pour travailler sur la largeur, mais dès que je l'utilise le poids sur rien de hauteur est affiché, mon code est le suivant:ANDROID linearlayout remplit l'espace restant en utilisant le poids

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" > 
    <LinearLayout android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:baselineAligned="true" android:weightSum="100"> 

     <com.example.test.MyImageView 
      android:id="@+id/test_img" 
      android:layout_height="0dp"   
      android:layout_width="wrap_content" 
      android:layout_weight="75" 
      android:scaleType="fitCenter"  
      /> 

     <Button 
     android:id="@+id/RedrawBtn" 
     android:layout_height="0dp"  
     android:layout_width="wrap_content"  
     android:layout_weight="25" 
     android:text="Button" /> 
    </LinearLayout> 
</RelativeLayout> 
+0

S'il vous plaît voir ma réponse, il va résoudre votre problème. –

Répondre

2

vous n'avez pas donné orientation à LinearLayout

<LinearLayout android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:baselineAligned="true" android:weightSum="100" 
    android:orientation="vertical"> 

    <com.example.test.MyImageView 
     android:id="@+id/test_img" 
     android:layout_height="0dp"   
     android:layout_width="wrap_content" 
     android:layout_weight="75" 
     android:scaleType="fitCenter"  
     /> 

    <Button 
    android:id="@+id/RedrawBtn" 
    android:layout_height="0dp"  
    android:layout_width="wrap_content"  
    android:layout_weight="25" 
    android:text="Button" /> 
</LinearLayout> 
1

essayer ce code

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" > 

    <LinearLayout android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:baselineAligned="true" 
    android:orientation="vertical"> 

     <com.example.test.MyImageView 
      android:id="@+id/test_img" 
      android:layout_height="0dp"   
      android:layout_width="wrap_content" 
      android:layout_weight="1" 
      android:scaleType="fitCenter"  
      /> 

     <Button 
     android:id="@+id/RedrawBtn" 
     android:layout_height="wrap_content"  
     android:layout_width="wrap_content"  
     android:text="Button" /> 
    </LinearLayout> 
</RelativeLayout> 
0

Ecrire ci-dessous le code au lieu de votre code, il résoudra votre problème.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical" > 

    <com.example.test.MyImageView 
     android:id="@+id/test_img" 
     android:layout_height="match_parent"   
     android:layout_width="wrap_content" 
     android:layout_weight="75" 
     android:scaleType="fitCenter" /> 

    <Button 
     android:id="@+id/RedrawBtn" 
     android:layout_height="match_parent"  
     android:layout_width="wrap_content"  
     android:layout_weight="25" 
     android:text="Button" /> 

</LinearLayout> 
Questions connexes