【发布时间】:2013-04-29 12:01:34
【问题描述】:
我在想,如果我只提供一层LinearLayout 作为 ListView 的行视图,它的边距将被忽略。
如果使用 ListView 的行视图,边距将被忽略
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="5dp"
但是,如果我提供双层LinearLayout,第一层作为“虚拟”层,它的边距不会被忽略。
我们将在 ListView 的行视图中有边距
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/buyPortfolioLinearLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="5dp"
我可以知道为什么会这样吗?
【问题讨论】:
-
我的观察是所有带有 layout 前缀的属性都是指这个 UI 元素与其父元素的关系,并且可以被父元素覆盖,而没有 的属性layout 指的是这个 UI 元素与其子元素的关系。你试过用“padding”代替“layout_margin”吗?
-
相同。在 LinearLayout 的最外层使用边距或填充也将被忽略。
标签: android