android:如何将填充添加到 FrameLayout 内的 LinearLayout

标签 android android-layout android-framelayout

我有一个包含很多 child 的 FrameLayout。其中一个 child 是 LinearLayout。我希望 LinearLayout 的宽度为 match_parent 但大约为 90%;这意味着我想添加某种 paddingLeft/RightmargingLeft/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/

相关文章:

android - 一个 Activity 中的多个 ListView

android - 使用新的 GridLayout 创建 3*3 网格

android - DialogFragment 被状态栏重叠

android - 以编程方式更改按钮可绘制

java - Retrofit2:如何正确检查response.body()的有效性?

android - 以编程方式关闭应用程序(知道包名称)

android - 在我的 Activity 中动态添加一个 fragment

android - 如何在android上使用正确的 View 拖动

android - 为 FrameLayout 内的所有自定义 View 触发 OnClickListener

android - 他们怎么称呼android图形服务器?