Android ImageButton 边框?

发布于 2024-09-08 17:22:13 字数 158 浏览 1 评论 0原文

我有一系列水平放置在 LinearLayout 中的 ImageButton。当我将 setBackgroundColor 设置为绿色时,这些 ImageButton 全部变成绿色矩形,所有连接都看起来像一个单独的条形。有没有一种方法可以指定这些按钮之间的边框,以便我知道一个按钮的起始位置和结束位置?

I have a series of ImageButtons horizontally laid out in a LinearLayout. When I do a setBackgroundColor to GREEN, these ImageButtons all become GREEN rectangles, all connected that look like one single bar. Is there a way I can specify a border between these buttons, so I know where one button starts and where it ends?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

喜爱纠缠 2024-09-15 17:22:13

空白视图会使您的布局变得臃肿。 Android 布局中有两个不同的概念,其中一个是 padding。填充将添加到布局的宽度,它定义从视图边框到视图内容的可用空间。背景颜色位于整个视图的后面,因此包括填充在内的整个区域都填充有背景颜色。

第二个概念是layout_margin 布局边距是从视图的可见边框到另一个边框所使用的空间。视图不能将自身绘制到边距空间中。

为按钮提供属性layout_margin应该可以帮助您在按钮之间拥有可见的空间,而无需为每对按钮添加另一个视图。

A blank View will bloat your Layout. There are two distinct concepts in the Android Layout one is the padding. Padding will be added to the width of the layout and it defines how much space is free from the boarder of the view to the content of the view. The backgroundcolor is behind the whole View therefore the whole area inclusive the padding is filled with the backgroundColor.

The second concept is layout_margin layout margin is the space that is used from the visible boarder of the view to another boarder. A View can not draw itself into the margin space.

Giving the button the attribute layout_margin should help you to have a visible space between the buttons without adding another view for each pair of buttons.

无名指的心愿 2024-09-15 17:22:13

要通过显示分隔符(类似于水平线)来在两个按钮之间留出间隙,您必须在两个按钮之间添加Blank View

因此插入空白视图会创建行分隔符。此分隔视图用于分隔按钮下方和按钮上方的区域:

     <View
     android:layout_height="2px"
     android:background="#DDFFDD"
     android:layout_marginTop="5dip"
     android:layout_marginBottom="5dip"/>

尝试一下。

享受!!

For making the gap between two buttons by displaying Separator (something like Horizontal line), you have to Add Blank View in between two buttons.

Thereby inserting a blank view creates a line separator. This separator view is used to separate the area below the buttons and above buttons:

     <View
     android:layout_height="2px"
     android:background="#DDFFDD"
     android:layout_marginTop="5dip"
     android:layout_marginBottom="5dip"/>

Try it.

Enjoy!!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文