首页 > 解决方案 > 使用 android:layout_margin 设置时 layout_marginBottom 无效

问题描述

在继续发布这个问题之前,我在 SO 上尝试了多个答案。这些都没有帮助。

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">
 
       <allosh.xvideo.player.views.PlayerVideoView
            android:layout_centerInParent="true"
            android:layout_alignParentLeft="true"
            android:layout_alignParentRight="true"
            android:layout_alignParentBottom="true"
            android:layout_alignParentTop="true"
            android:layout_width="match_parent"
            android:layout_height="match_parent"/>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_margin="5dp"
            android:layout_alignParentBottom="true"
            android:layout_marginBottom="100dp"/>
     </RelativeLayout>
</RelativeLayout>

LinearLayoutandroid:layout_marginBottom="100dp"不做任何事情,但android:layout_margin="5dp"具有可见的效果。
我不仅在寻找解决方案,而且还在寻找适当的解释。这将是有益的和感激的。

标签: androidxmlandroid-layout

解决方案


你应该:

  1. 设置 marginLeft、marginRight 和 marginTop 而不是 margin
  2. 从 PlayerVideoView 中删除 layout_alignParentBottom
  3. 为您的 PlayerVideoView 设置 alignBottom
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">
 
       <allosh.xvideo.player.views.PlayerVideoView
            android:layout_centerInParent="true"
            android:layout_alignParentLeft="true"
            android:layout_alignParentRight="true"
            android:layout_alignBottom="@+id/linear1"
            android:layout_alignParentTop="true"
            android:layout_width="match_parent"
            android:layout_height="match_parent"/>

        <LinearLayout
            android:id="@+id/linear1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginRight="5dp"
            android:layout_marginLeft="5dp"
            android:layout_marginTop="5dp"
            android:layout_alignParentBottom="true"
            android:layout_marginBottom="100dp"/>
     </RelativeLayout>
</RelativeLayout>

推荐阅读