使用android:layout_margin设置时,layout_margin按钮无效
在继续发布这个问题之前,我尝试了多个答案。这些都毫无帮助使用android:layout_margin设置时,layout_margin按钮无效,android,xml,android-layout,Android,Xml,Android Layout,在继续发布这个问题之前,我尝试了多个答案。这些都毫无帮助 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <RelativeLayout
<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\u marginBottom=“100dp”
没有任何作用,而android:layout\u margin=“5dp”
具有明显的效果。我不仅在寻找解决方案,也在寻找一个恰当的解释。这将是有益且值得赞赏的。在此处设置
android:layout\u margin
属性覆盖android:layout\u marginBottom
。因此,如果需要单独的底部边距,则必须分别指定开始边距、结束边距和顶部边距
如果您对技术说明感兴趣,则布局参数由
MarginLayoutParams
类读取。这是来自构造函数的简化代码段:
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);
...
}
如您所见,他们首先读取“所有边”边距属性,然后只有在未设置该属性时,才继续检查其他边距属性。具体而言,他们按以下顺序检查:
android:layout\u margin
android:layout\u marginorizontal
,android:layout\u marginorical
android:layout\u marginLeft
,android:layout\u marginBottom
等感谢您的努力和解释。这完全有道理。我真的试着从这个布局中删除每一个空白属性,除了引起这个问题的那个!