简体   繁体   中英

How to use support layout_columnWeight in a style?

I think this snippet from values/styles.xml says it all:

<!-- 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:

    <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. (It works fine if I set it in the layout file: 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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM