[英]layout_marginBottom has no effect when set with android:layout_margin
在继续发布这个问题之前,我在 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>
LinearLayout 的android:layout_marginBottom="100dp"
什么都不做,而android:layout_margin="5dp"
有一个可见的效果。
我不仅在寻找解决方案,而且还在寻找适当的解释。 这将是有益的和感激的。
在此处设置android:layout_margin
属性会覆盖android:layout_marginBottom
。 因此,如果您想要单独的下边距,则必须分别指定开始、结束和上边距。
如果您对技术解释感兴趣,可以通过MarginLayoutParams
class 读取布局参数。 这是构造函数的简化片段:
int margin = a.getDimensionPixelSize(R.styleable.ViewGroup_MarginLayout_layout_margin, -1);
if (margin >= 0) {
leftMargin = margin;
topMargin = margin;
rightMargin= margin;
bottomMargin = margin;
} else {
int horizontalMargin = a.getDimensionPixelSize(R.styleable.ViewGroup_MarginLayout_layout_marginHorizontal, -1);
...
}
正如你所看到的,他们首先读取'all-sides'边距属性,然后只有当它未设置时,他们才会继续检查其他边距属性。 具体来说,他们按以下顺序检查:
android:layout_margin
android:layout_marginHorizontal
, android:layout_marginVertical
android:layout_marginLeft
, android:layout_marginBottom
等。你应该:
<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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.