2012-12-21 30 views
1

我試圖讓我的控件顯示一個控件,該控件具有一個按鈕和一個佔用剩餘空間的圖像。我一直在尋找使用權,我可以得到它的寬度工作,但只要我用身高沒有重量顯示,我的代碼如下:ANDROID linearlayout使用重量填充剩餘空間

<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

請看我的回答,它會解決你的問題。 –

回答

2

你沒有給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

試試這個代碼下面的代碼,而不是你的代碼

<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

寫,這將解決您的問題。

<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>