我试图得到我的控件,以便我显示一个控件,有一个按钮和占用剩余空间的图像。我一直在看使用权重,我可以让它在宽度上工作,但一旦我使用高度上的权重没有显示,我的代码如下:
<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>
你没有给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>
试试这个代码
<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>
用下面的代码代替你的代码,它会解决你的问题。
<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>