简体   繁体   English

在同一行中显示四个按钮,它们之间没有空格?

[英]Show four button in same line without any space between them?

I want to have four button under action bar like this. 我想在操作栏下面有四个按钮。 But the problem is I can not remove the space between the buttons. 但是问题是我无法删除按钮之间的空间。 I used negative margin but it does not look like this. 我使用负边距,但它看起来不是这样。 So my question is how can I achieve this design? 所以我的问题是如何实现这种设计? 理想的设计

I did so far 我到目前为止

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

and the output is 输出是 在此处输入图片说明

You need to add to buttons borderless style. 您需要向按钮添加无边界样式。

style="?android:attr/borderlessButtonStyle"

It is a default system style, that using in themes, to create button bars. 这是默认的系统样式,用于在主题中创建按钮栏。

Without it, always will be a small margin. 没有它,总是会有很小的余地。 You can read about it here , and here , from official documentation. 您可以在此处此处从官方文档中阅读有关内容。 It allows you to create button bars, like in your screenshot. 它允许您像在屏幕截图中一样创建按钮栏。

Try this : Put all your buttons within Horizontal linear layout and set the width and height as follows, 尝试以下操作:将所有按钮置于“水平”线性布局内,并按如下所示设置宽度和高度,

    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_weight="0.25"

You can use linear layout for view button in same line. 您可以在同一行中为视图按钮使用线性布局。 Using layout_weight 使用layout_weight

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 将按钮放在一行中,所有按钮之间的空格相同 - put button in one line with same space between all button 如何使三个视图始终处于同一行,并且它们之间始终具有相同的间距? - How can i make the three views always be in one line and also always have the same amount of space between them? 在linearlayout中的按钮之间创建相同的空格 - make same space between button in linearlayout 如何在 Android 上显示按钮之间没有空格? - How can I display buttons without space between them on Android? android如何在按钮之间留出一些空间并在每个按钮上方添加白线 - android how to make some space between buttons and make white line above each of them 两个textview都在同一位置显示值,我该如何更改它们之间的空间? - both textview show value on same location how do i change or space inbetween them? 2个可绘制按钮水平方向上2个按钮和onclick之间没有空格,更改可绘制按钮的颜色 - 2 drawable button Horizontally without space between 2 button and onclick change drawable button color Android-相对布局在水平方向上对齐项目,以便它们之间始终具有相同的空间 - Android - Relative layout align items in horizontal so that they always have same space in between them 重叠图像(如果没有足够的空间来显示) - Overlap images if there is not enough space to show them 行和输入之间的EditText空间 - EditText space between the line and the input
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM