在您的具体情况,你可以使两个ImageViews
占据父母的宽度的50%,而不使用权用这样的块:
<RelativeLayout android:layout_width="match_parent" android:layout_height="0dp"
android:layout_weight="your_value">
<View android:id="@+id/anchor" android:layout_width="0dp"
android:layout_height="match_parent" android:layout_centerHorizontal="true"/>
<ImageView android:layout_width="wrap_content"
android:layout_height="match_parent" android:layout_alignParentLeft="true"
android:layout_alignRight="@id/anchor" />
<ImageView android:layout_width="wrap_content"
android:layout_height="match_parent" android:layout_alignParentRight="true"
android:layout_alignLeft="@id/anchor" />
</RelativeLayout>
根据我的经验,我一直担心表现不好,但从未注意到它。我在过去读过它,看起来这可能是一个问题,尤其是如果你对列表视图(列表视图的每一行具有嵌套权重)进行此操作,并在列表中显示1000个视图。但从静态角度来看,您可能不必担心 – Jameo
hi @jameo感谢您的回复。正如我所说,我正在学习android,并且我想从开始就以正确的方式进行。所以,如果谷歌说这是不好的方法,我想避免它 – Chux
基本上,你可能能够完成这个不同的方式,但它会过于复杂,并不适用于所有情况。只是因为android警告你并不意味着它的__wrong__ – Jameo