在同一行显示四个按钮,它们之间没有任何 space?
Show four button in same line without any space between them?
我想在这样的操作栏下有四个按钮。但问题是我无法删除按钮之间的 space 。我使用了负边距,但它看起来不像这样。所以我的问题是我怎样才能实现这个设计?
到目前为止我做到了
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Sports"
android:id="@+id/sports"
android:layout_marginRight="-8dp"/>
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Political"
android:id="@+id/political"
android:layout_toRightOf="@+id/sports"/>
输出是
试试这个:
将所有按钮放在水平线性布局中,并按如下方式设置宽度和高度,
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.25"
您需要为按钮添加无边框样式。
style="?android:attr/borderlessButtonStyle"
这是默认的系统样式,在主题中使用,用于创建按钮栏。
没有它,永远都是微不足道的。您可以从官方文档中了解它 here, and here。它允许您创建按钮栏,就像您的屏幕截图中那样。
您可以对同一行的视图按钮使用线性布局。使用 layout_weight
我想在这样的操作栏下有四个按钮。但问题是我无法删除按钮之间的 space 。我使用了负边距,但它看起来不像这样。所以我的问题是我怎样才能实现这个设计?
到目前为止我做到了
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Sports"
android:id="@+id/sports"
android:layout_marginRight="-8dp"/>
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Political"
android:id="@+id/political"
android:layout_toRightOf="@+id/sports"/>
输出是
试试这个: 将所有按钮放在水平线性布局中,并按如下方式设置宽度和高度,
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.25"
您需要为按钮添加无边框样式。
style="?android:attr/borderlessButtonStyle"
这是默认的系统样式,在主题中使用,用于创建按钮栏。
没有它,永远都是微不足道的。您可以从官方文档中了解它 here, and here。它允许您创建按钮栏,就像您的屏幕截图中那样。
您可以对同一行的视图按钮使用线性布局。使用 layout_weight