的LinearLayout,RelativeLayout的,等如预期利润率不工作 [英] LinearLayout, RelativeLayout, etc. margins do not work as expected

查看:152
本文介绍了的LinearLayout,RelativeLayout的,等如预期利润率不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好像在组布局边距不工作。

Margins in group layouts do not seem to work.

例如,

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_margin="40dip"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <Button
        android:id="@+id/button"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:text="I'm a button" />

</LinearLayout>

应显示在各方面40P利润率按钮。然而,它有80P边距在右侧和底部。

should display a button with 40p margins on all sides. However, it has 80p margins on the right and bottom.

我是不是做错了什么? 这是一个错误?

Am I doing something wrong? Is this a bug?

一个解决方法是利用重力,但这仅适用于甚至利润。

A workaround would be to use gravity, but this only works with even margins.

顺便说一句,有一个类似的问题<一href="http://stackoverflow.com/questions/1818633/relativelayout-margins-inside-a-listview-are-not-displayed">posted这里但一直没有得到答复。

BTW, there is a similar question posted here but has not been answered.

推荐答案

安卓填充=40dp上的LinearLayout或安卓layout_margin =40dp上的按钮会给你你想要的效果。填充限定次边缘和其内容之间的空间,布局定义裕度上的视图的侧面额外空间。

android:padding="40dp" on the LinearLayout or android:layout_margin="40dp" on the Button will give you the effect you want. Padding defines the space between a views edges and its content, layout margin defines extra space on the sides of a view.

这篇关于的LinearLayout,RelativeLayout的,等如预期利润率不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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