【发布时间】:2015-10-10 16:02:16
【问题描述】:
我知道这个问题问得很糟糕。但我只想知道如何用它们之间的白色小边框做下图所示的事情 在android布局中?有人可以帮帮我吗?
【问题讨论】:
我知道这个问题问得很糟糕。但我只想知道如何用它们之间的白色小边框做下图所示的事情 在android布局中?有人可以帮帮我吗?
【问题讨论】:
一种方法是使用 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 完全没用。
一种方法是使用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>
【讨论】:
在RelativeLayout 中创建第一个Button,然后创建一个LinearLayout,其高度与RelativeLayout 相同,宽度为2dp,属性android:background="#fff" 和前android:layout_toRightOf:"@+id:button_1",然后创建第二个具有属性 ex android:layout_toRightOf:"@+id:linear_layout1" 的按钮
【讨论】: