组布局中的边距似乎不起作用。
例如,
<?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 的边距。
我做错了吗? 这是一个错误吗?
一种解决方法是使用重力,但这仅适用于均匀边距。
顺便说一句,有一个类似的问题 posted here但尚未得到答复。
最佳答案
android:padding="40dp"
在 LinearLayout 或 android:layout_margin="40dp"
在 Button 会给你你想要的效果。内边距定义 View 边缘及其内容之间的空间,布局边距定义 View 两侧的额外空间。
关于android - LinearLayout、RelativeLayout 等边距不按预期工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5412847/