有没有办法完全消除包含按钮的 LinearLayout 中的填充? [英] Is there a way to completely eliminate padding in a LinearLayout containing buttons?

查看:23
本文介绍了有没有办法完全消除包含按钮的 LinearLayout 中的填充?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试了以下尝试以水平线性布局显示两个按钮,按钮的边缘与线性布局的边框齐平.令我惊讶的是,我发现按钮和线性布局的左、右和下边缘之间总是有填充.只有按钮的顶部边缘与线性布局的边界齐平.这是为什么?有没有办法控制这种行为?非常感谢.

I tried the following to try to display two buttons in a horizontal linear layout, with the edges of the buttons flush with the border of the linear layout. To my surprise, I found that there is always still padding between the buttons and the left, right and bottom edges of the linear layout. Only the top edges of the buttons end up flush with the border of the linear layout. Why is that? And is there a way to control this behavior? Thanks much.

<LinearLayout android:orientation="horizontal"
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:background="#777"
  android:padding="0dip"
  android:layout_margin="0dip">
  <Button android:id="@+id/feeling_done_button"
     android:text="@string/done_button_label"
     android:layout_height="wrap_content"
     android:layout_width="match_parent"
     android:layout_weight="1"
     android:padding="0dip"
     android:layout_margin="0dip"/>
  <Button android:id="@+id/feeling_cancel_button"
     android:text="@string/cancel_button_label"
     android:layout_height="wrap_content"
     android:layout_width="match_parent"
     android:layout_weight="1"
     android:padding="0dip"
     android:layout_margin="0dip"/></LinearLayout>

推荐答案

如果你的意思是你想让它们被推到边缘,一个像素一个像素,你需要使用你自己的 9-patch 作为按钮背景,因为 Android 中的默认背景在其 9 补丁背景的边框周围有一些额外的像素.有关此示例,请查看 SDK 文件夹中的文件:

If you're meaning you want them to be pushed to the edge, pixel for pixel, you'll need to use your own 9-patch for the button background, as the default one in Android has a few extra pixels around the border of its 9-patch background. For an example of this, look at the file in your SDK folder under:

platforms/android-8/data/res/drawable-hdpi/btn_default_transparent_normal.9.png

例如,这是我得到的默认值:

For example, this is what I get with the default:

使用我之前制作的自定义 9 补丁:

And with a custom 9-patch I had made earlier:

这篇关于有没有办法完全消除包含按钮的 LinearLayout 中的填充?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆