我正在尝试获取我的控件,以便显示一个控件,该控件具有一个按钮和一个占据剩余空间的图像。我一直在考虑使用权重,我可以让它在宽度上工作,但是一旦我在高度上使用权重,就什么都没有显示,我的代码如下:
<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>
最佳答案
你还没有给 LinearLayout orientation
<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>
关于ANDROID linearlayout 使用权重填充剩余空间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13988715/