简体   繁体   English

如何在样式中使用支持 layout_columnWeight?

[英]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_gravitylayout_columnWeight

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 API 21 之前支持 `layout_columnWeight` 和 `layout_rowWeight`? - How to support `layout_columnWeight` and `layout_rowWeight` in pre API 21? 如何以编程方式将 android:layout_columnWeight="1" 设置为 android 支持 v7 Gridlayout 中的元素 - How do I set android:layout_columnWeight="1" programmatically to an element in an android support v7 Gridlayout 如何从代码中设置“ app:layout_columnWeight”? - how set “app:layout_columnWeight” from code? 如何以编程方式添加GridLayout子项的layout_columnWeight? - How to set layout_columnWeight for a GridLayout child when added programmatically? 如何以编程方式将app:layout_columnWeight和app:layout_rowWeight设置为GridLayout的子级 - how to set app:layout_columnWeight and app:layout_rowWeight to GridLayout's child programmatically 在包“android”中找不到属性“layout_columnWeight”的资源标识符 - No resource identifier found for attribute 'layout_columnWeight' in package 'android' 在 Gridlayout 中的 MaterialCardView 中找不到属性 layout_columnWeight - Attribute layout_columnWeight not found in MaterialCardView inside Gridlayout Android GridLayout layout_columnWeight="1" 和 layout_width="0dp" 以编程方式 - Android GridLayout layout_columnWeight="1" and layout_width="0dp" programmatically 如何使用 Java 设置 columnWeight - How to set columnWeight with Java 如何以编程方式设置cardView的columnWeight - How to set columnWeight of cardView programmatically
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM