簡體   English   中英

將屏幕分為3個相等的部分-ImageButtons

[英]Split the screen in 3 equal parts - ImageButtons

我有3個ImageButton,每個文本下方都有一個文本,並且它們之間有一個分隔符。 我希望它們占據屏幕的相等空間,每個占1/3。 我嘗試了權重分量,將其0和布局的weightSum相等(等於“ 3”),但這沒有用。 這是到目前為止的代碼:

<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>

您需要將android:layout_weight="1"放入包含ImageViewTextViewLinearLayout中。 只要layout_weights相同,就不需要放入weightSum。 用作分隔符的視圖應具有android:layout_weight="0"

嘗試這個:

<?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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM