我试图在一个 RelativeLayout 中垂直显示两个 ImageView,每个 imageView 有 50% 的权重,但显示只显示一个 ImageView。
代码:
<RelativeLayout
android:id="@+id/layout_board"
android:layout_width="match_parent"
android:layout_height="450dp"
android:background="@color/colorPrimaryDark"
android:weightSum="2">
<ImageView android:id="@+id/imageView11"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
android:background="@color/colorAccent"
android:adjustViewBounds="true"
android:scaleType="fitXY"/>
<ImageView android:id="@+id/imageView21"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
android:background="@color/colorAccent"
android:adjustViewBounds="true"
android:scaleType="fitXY"/>
</RelativeLayout>
请帮忙!
最佳答案
android:layout_weight
不是 RelativeLayout
的属性,它是 LinearLayout
的属性。因此,您可以将父布局更改为 LinearLayout
或者您可以使用 PercentRelativeLayout
代码 fragment
<android.support.percent.PercentRelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
app:layout_widthPercent="50%"
app:layout_heightPercent="50%"
app:layout_marginTopPercent="25%"
app:layout_marginLeftPercent="25%"/>
</android.support.percent.PercentRelativeLayout>
关于android - 为什么 layout_weight 在 RelativeLayout 中不能正常工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40986772/