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

3 回答 3

2

你还没有给orientationLinearLayout

<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>
于 2012-12-21T10:52:10.787 回答
2

试试这个代码

<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>
于 2012-12-21T10:53:20.880 回答
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>
于 2012-12-21T11:42:17.140 回答