【问题标题】:How to divide two buttons into two halves of the layout?如何将两个按钮分成两半布局?
【发布时间】:2015-10-10 16:02:16
【问题描述】:

我知道这个问题问得很糟糕。但我只想知道如何用它们之间的白色小边框做下图所示的事情 在android布局中?有人可以帮帮我吗?

two buttons

【问题讨论】:

    标签: android xml button layout


    【解决方案1】:

    一种方法是使用 LinearLayout 和 layout_weight 参数,您可以这样做:

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:orientation="horizontal"
        android:weightSum="2.0"
        style="?attr/buttonBarStyle">
        <Button
            android:id="@+id/buttonOne"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            style="?attr/buttonBarButtonStyle"
            android:text="Button One"/>
        <View
            android:layout_width="1dp"
            android:layout_height="match_parent"
            android:background="@android:color/white"/>
        <Button
            android:id="@+id/buttonTwo"
            style="?attr/buttonBarButtonStyle"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:text="Button Two"/>
    </LinearLayout>
    

    风格就是不费吹灰之力就让它在酒吧里好看。

    【讨论】:

    • weightSum 完全没用。
    【解决方案2】:

    一种方法是使用layout_weight(如下面的代码)或者你可以使用gridlayout

    <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"  android:orientation="horizontal">
    <Button
                android:gravity="center"
                android:layout_weight="0.45"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                />
    
    <ImageView  
                android:layout_weight="0.1"
                    android:layout_width="0dp"
                    android:background="@color/white"
                    android:layout_height="wrap_content" />
    <Button
                    android:gravity="center"
                    android:layout_weight="0.45"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    />
    </LinearLayout>
    

    【讨论】:

      【解决方案3】:

      RelativeLayout 中创建第一个Button,然后创建一个LinearLayout,其高度与RelativeLayout 相同,宽度为2dp,属性android:background="#fff" 和前android:layout_toRightOf:"@+id:button_1",然后创建第二个具有属性 ex android:layout_toRightOf:"@+id:linear_layout1" 的按钮

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-05-25
        • 2013-12-06
        • 2012-05-26
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多