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

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

问题描述

我尝试以下来尝试显示两个按钮在水平线性布置,以与线性布局的边界平齐的按钮的边缘。令我惊讶的是,我发现总有仍然按钮和左,右和线性布局的底部边缘之间填充。的按钮中的唯一的顶边结束平齐线性布局的边界。这是为什么?而且是有办法控制这种行为?谢谢了。

 <的LinearLayout机器人:方向=横向
  机器人:layout_width =match_parent
  机器人:layout_height =WRAP_CONTENT
  机器人:后台=#777
  机器人:填充=0dip
  机器人:layout_margin =0dip>
  <按钮机器人:ID =@ + ID / feeling_done_button
     机器人:文本=@字符串/ done_button_label
     机器人:layout_height =WRAP_CONTENT
     机器人:layout_width =match_parent
     机器人:layout_weight =1
     机器人:填充=0dip
     机器人:layout_margin =0dip/>
  <按钮机器人:ID =@ + ID / feeling_cancel_button
     机器人:文本=@字符串/ cancel_button_label
     机器人:layout_height =WRAP_CONTENT
     机器人:layout_width =match_parent
     机器人:layout_weight =1
     机器人:填充=0dip
     机器人:layout_margin =0dip/>< / LinearLayout中>
 

解决方案

如果你的意思,你希望他们推到边缘,一个像素,你需要用你自己的9补丁按钮背景下,作为默认的在Android有围绕其9贴片背景边境一些额外的像素。对于这样的一个例子,在看文件的SDK文件夹:

平台/ Android的-8 /数据/ RES /绘制,华电国际/ btn_default_transparent_normal.9.png

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

和一个自定义9补丁我曾在早些时候:

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>

解决方案

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:

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

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

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