Questions tagged [android-gravity]

64 questions
1457
votes
22 answers

What is the difference between gravity and layout_gravity in Android?

I know we can set the following values to the android:gravity and android:layout_gravity properties: center center_vertical center_horizontal, etc. But I am confused regarding both of these. What is the difference between the usage of…
Paresh Mayani
  • 127,700
  • 71
  • 241
  • 295
37
votes
5 answers

Change gravity of image drawable in textview

I've added image Drawable start in a TextView . Problem is i cant control the gravity of that Drawable in TextView What i need to achieve What i have achieved so far This is my TextView
24
votes
2 answers

How to check gravity flags in a custom Android View?

The problem I have a custom Android view in which I want get the user set gravity in order to layout the content in onDraw. Here is a simplified version that I am using in onDraw: // check gravity if ((mGravity & Gravity.CENTER_VERTICAL) ==…
Suragch
  • 484,302
  • 314
  • 1,365
  • 1,393
21
votes
11 answers

Center hint and EditText vertically in TextInputLayout

I am using a TextInputLayout to show a hint but I am not able to center it vertically. I always get this: And I would like to center the hint vertically when there is no text in the EditText / TextInputEditText. I have tried the basic ideas…
8
votes
2 answers

android:gravity="start" in RTL aligns the text to left not right

While testing my layout on a device with RTL language (Arabic) I found that TextView with gravity:start keeps aligning the text to the left instead of right ! I tried android:textAlignment="viewStart" and it works correctly but due to API reqs I…
Bialy
  • 905
  • 2
  • 12
  • 22
8
votes
7 answers

How to make error message in TextInputLayout appear in center

Currently it looks as in attached with this layout:
cgr
  • 4,578
  • 2
  • 28
  • 52
7
votes
3 answers

Android: how to align 2 images on a splash screen

I would like to use a splah screen containing 2 images: the main image must be fully center the secondary image must be center between the bottom and the main image The expected render is something like this: But I don't see how to get this, and…
Gold.strike
  • 1,269
  • 13
  • 47
5
votes
2 answers

Android iconGravity not working for MaterialButton with CircularProgressIndicator

I've created a custom view that extends MaterialButton that replaces the drawable with a CircularProgressIndicator when it's loading. However when I replace the drawable with the CircularProgressIndicator the iconGravity doesn't work anymore. I…
4
votes
1 answer

How to make SwiftUI Text multilineTextAlignment start from Top and Center

How can I make the image and text alignment same as 3 other in SwiftUI LazyVGrid as I expected in image below? I think the problem is how to make the text start from top if the text is multiline. In Android I can use gravity="top|center" but in…
doema
  • 503
  • 4
  • 7
3
votes
1 answer

PopupMenu submenu doesn't respect the gravity alignment

In Android API 23, I have a Popup menu with submenu items. I have defined the gravity to the end, as shown popupMenu = new PopupMenu(this, v, Gravity.END); popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { @Override …
3
votes
1 answer

Different Gravity of two textviews in a horizontal Linear Layout

I am using the following code and when I set gravity to the first textview to center, automatically the second textview's text is also getting aligned with the first one. Even Though I set the gravity of second view to top
Mani Sankar
  • 800
  • 1
  • 9
  • 19
2
votes
2 answers

Is there any alternative for Toast.setGravity() to support in android 11 and above devices?

Is there any way that I can position my Toast message in the center of the screen? Since Toast.setGravity() is not supported for Android 11 and above devices(API level 30 and above) as per android official documentation. I am not able to position my…
Allan Antony
  • 21
  • 1
  • 5
2
votes
2 answers

"android:gravity" for custom button is not applying when defined in styles.xml

I just can't center (vertically and horizontally) text in a Button I defined in styles.xml (works properly when all attributes are in layout) Originally all attributes were set directly in the layout, but I have lots of fragments where all buttons…
Gilles
  • 229
  • 1
  • 3
  • 11
2
votes
2 answers

Layout attributes in XML code those are ignored when using addView method

I'm korean, The image under is used korean language. Well.. This fact isn't important. I tried to add the custom view, In Linear layout, And It's be in linear layout successfully. But It's not on center horizontal. I did surely set the gravity of…
Sinho
  • 45
  • 10
1
2 3 4 5