Can I specify multiple gravity values ​​in the spinner custom_style.xml element?

I have textview.xml which is an element style for clips.

<TextView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:gravity="left|center_horizontal" android:textSize="18sp"> </TextView> 

I know that you can specify both (Gravity.LEFT | Gravity.CENTER_HORIZONTAL) and in xml, which does not work - the text moves only to the left.

+46
android android-layout gravity
Mar 08 2018-11-18T00:
source share
1 answer

87element,

I suppose you intended to use layout_gravity , are you only using gravity ??

Yes, you can combine two of these layout_gravity attributes with '|' as stated in the documentation: http://developer.android.com/reference/android/R.attr.html#layout_gravity

But even using layout_gravity instead of just gravity (as indicated in his comment), the settings you are trying to combine do not make sense. You say that basically align the left and center on the same line. Both left and center_horizontal in this case refer to horizontal positions.

Where are you trying to align TextView with parent?

Your parent layout is like a grid where you can select a position:

| [1] [2] [3] |

| [4] [5] [6] |

| [7] [8] [9] |

  • Top left: android:layout_gravity="top|left"

  • Top-Center: android:layout_gravity="top|center_horizontal"

  • Up-Right: android:layout_gravity="top|right"

  • Center-left: android:layout_gravity="center_vertical|left"

  • Very center: android:layout_gravity="center"

  • Center-Right: android:layout_gravity="center_vertical|right"

  • Bottom left: android:layout_gravity="bottom|left"

  • Bottom Center: android:layout_gravity="bottom|center_horizontal"

  • Bottom-right: android:layout_gravity="bottom|right"

Hope this helps!

+142
Mar 08 '11 at 18:49
source share



All Articles