我有一个包含很多 child 的 FrameLayout。其中一个 child 是 LinearLayout。我希望 LinearLayout 的宽度为 match_parent
但大约为 90%;这意味着我想添加某种 paddingLeft/Right
或 margingLeft/Right
。但是当我添加填充或边距时,它不会应用于图形布局。我该如何正确执行此操作?
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/blue" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_horizontal"
android:background="@color/red"
android:marginLeft="20dp"
android:marginRight="20dp"
android:orientation="vertical" >
....
最佳答案
你有
android:marginLeft="20dp"
android:marginRight="20dp"
改为:
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
如果还是不行,把这个布局放在另一个布局里面,然后把边距设置到另一个布局。
关于android:如何将填充添加到 FrameLayout 内的 LinearLayout,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21592738/