[英]Split the screen in 3 equal parts - ImageButtons
I have 3 ImageButtons with texts under each and a separator between them. 我有3个ImageButton,每个文本下方都有一个文本,并且它们之间有一个分隔符。 I want them to occupy equal space of the screen, 1/3rd each. 我希望它们占据屏幕的相等空间,每个占1/3。 I tried the weight component, equalizing it 0 and weightSum
of the layout (equal to "3") but that didn't work. 我尝试了权重分量,将其0和布局的weightSum
相等(等于“ 3”),但这没有用。 Here is the code so far: 这是到目前为止的代码:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_gravity="center">
<LinearLayout
style="@style/..."
android:layout_marginLeft="15dp">
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/pic"/>
<TextView
style="@style/TextImageUploader"
android:text="@string/..."/>
</LinearLayout>
<View
android:layout_width="0.5dp"
android:layout_height="match_parent"
android:background="@color/..."/>
<LinearLayout
style="@style/..."
android:layout_marginLeft="15dp">
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/pic"/>
<TextView
style="@style/TextImageUploader"
android:text="@string/..."/>
</LinearLayout>
<View
android:layout_width="0.5dp"
android:layout_height="match_parent"
android:background="@color/blue_800"/>
<LinearLayout
style="@style/..."
android:layout_marginLeft="15dp">
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/pic"/>
<TextView
style="@style/TextImageUploader"
android:text="@string/..."/>
</LinearLayout>
</LinearLayout>
You need to put android:layout_weight="1"
in the LinearLayout
containing the ImageView
and TextView
. 您需要将android:layout_weight="1"
放入包含ImageView
和TextView
的LinearLayout
中。 As long as the layout_weights are the same, you don't need to put in a weightSum. 只要layout_weights相同,就不需要放入weightSum。 The View that serves as a separator should have android:layout_weight="0"
用作分隔符的视图应具有android:layout_weight="0"
try this: 尝试这个:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_gravity="center"
xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout
style="@style/..."
android:layout_weight="1"
android:layout_width="0dp"
android:layout_marginLeft="15dp">
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/pic"/>
<TextView
style="@style/TextImageUploader"
android:text="@string/..."/>
</LinearLayout>
<View
android:layout_width="0.5dp"
android:layout_height="match_parent"
android:background="@color/..."/>
<LinearLayout
style="@style/..."
android:layout_weight="1"
android:layout_width="0dp"
android:layout_marginLeft="15dp">
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/pic"/>
<TextView
style="@style/TextImageUploader"
android:text="@string/..."/>
</LinearLayout>
<View
android:layout_width="0.5dp"
android:layout_height="match_parent"
android:background="@color/blue_800"/>
<LinearLayout
style="@style/..."
android:layout_weight="1"
android:layout_width="0dp"
android:layout_marginLeft="15dp">
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/pic"/>
<TextView
style="@style/TextImageUploader"
android:text="@string/..."/>
</LinearLayout>
</LinearLayout>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.