我有一个包含LinearLayout,它有一个与之关联的样式,为容器提供20dp的填充。这对99%的内部元素非常有用。可能有1个元素我想在屏幕上扩展(android:layout_width =“match_parent”)并忽略包含LinearLayout的填充集。这可能吗?或者,我是否需要从包含LinearLayout中删除样式并将其单独应用于其他每个元素?
(为简洁而排除了一些属性)
<LinearLayout
android:padding="20dp">
<TextView
android:id="@+id/txtTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/txtDate"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<!-- Would like this to ignore padding, extend fully. -->
<TextView
android:id="@+id/txtExperienceTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="@style/sub_header_title" />
</LinearLayout>
答案 0 :(得分:3)
是的,你真的不能选择那样的。我将从LinearLayout中删除填充并将margin
应用于子项。
为了扩展loeschg在下面的评论中所说的内容,我建议使用“儿童风格”。由于看起来每个孩子只需要左/右边距,它会节省一些打字并且看起来更干净,每个孩子只有一条线,而不是分别在每个孩子上设置左右。
答案 1 :(得分:0)
你不能伸出容器。如果您有异常,请将style
应用于元素而不是容器。
答案 2 :(得分:-1)
是它会忽略它,你写的布局是这样的。
一般思考
int x = 7;
x = 20;
Show me that x = 7; ---You wanted to do something like this whit your layout
<TextView
android:id="@+id/txtTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/txtDate"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<!-- Would like this to ignore padding, extend fully. -->
<TextView
android:id="@+id/txtExperienceTitle"
style="@style/sub_header_title" // --- Style before adding laout_width if you want the layout to be match_parent
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>