[英]How to use support layout_columnWeight in a style?
I think this snippet from values/styles.xml says it all:我认为 values/styles.xml 中的这个片段说明了一切:
<!-- Style for the label above a button -->
<style name="baseLabel">
<item name="android:gravity">center</item>
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_columnWeight">1</item>
<item name="android:layout_gravity">center_horizontal|fill_horizontal</item>
</style>
And a corresponding entry from layout/main.xml might look like: layout/main.xml 中的相应条目可能如下所示:
<TextView
style="@style/baseLabel" android:text="@string/lr12"
app:layout_row="0"
app:layout_column="1" />
There are no build errors, but the layout_gravity attribute has had no effect.没有构建错误,但 layout_gravity 属性无效。 (It works fine if I set it in the layout file:
app:layout_gravity="center_horizontal|fill_horizontal
) (如果我在布局文件中设置它就可以正常工作:
app:layout_gravity="center_horizontal|fill_horizontal
)
You're setting android:layout_gravity
in your style, but app:layout_gravity
in what you say you're setting in the layout file.你在你的风格中设置了
android:layout_gravity
,但是app:layout_gravity
在你所说的你在布局文件中设置的内容中。 Those attributes need to match if you want them to do the same thing, so you should be using layout_gravity
and layout_columnWeight
in your style.如果你想让它们做同样的事情,这些属性需要匹配,所以你应该在你的样式中使用
layout_gravity
和layout_columnWeight
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.