[英]How to set the same width for 3 buttons in android RelativeLayout?
[英]How to set RelativeLayout's width same as sibling View?
所以我有这样的布局:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="center">
<RelativeLayout
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:orientation="horizontal">
<ImageView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:src="@drawable/advantage_1" />
<ImageView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:src="@drawable/advantage_2" />
</RelativeLayout>
<ImageView
android:id="@+id/lower_image_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/line" />
</LinearLayout>
由于在RelativeLayout内部对齐视图,因此它会填满整个屏幕。 如何设置RelativeLayout的宽度与较低的ImageView(lower_image_view)相同?
尝试这样。 主要思想是将RelativeLayout
和ImageView
放在另一个RelativeLayout
。 然后设置android:layout_alignLeft="@+id/lower_image_view"
和android:layout_alignRight="@+id/lower_image_view"
孩子的RelativeLayout
。 这将实现ImageView
的宽度。 您可能需要修改此设置以实现所需的结果,但是您知道了:)
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="center">
<RelativeLayout
android:id="@+id/parentRelativeLayout"
android:layout_height="wrap_content"
android:layout_width="wrap_content">
<RelativeLayout
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_alignLeft="@+id/lower_image_view"
android:layout_alignRight="@+id/lower_image_view"
android:orientation="horizontal">
<ImageView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:src="@drawable/ic_launcher" />
<ImageView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:src="@drawable/ic_launcher" />
</RelativeLayout>
<ImageView
android:id="@+id/lower_image_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/ic_launcher" />
</RelativeLayout>
</LinearLayout>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.