Questions tagged [android-gravity]

60 questions
1395
votes
20 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
  • 122,920
  • 69
  • 234
  • 290
26
votes
4 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
22
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
  • 364,799
  • 232
  • 1,155
  • 1,198
17
votes
9 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
6 answers

How to make error message in TextInputLayout appear in center

Currently it looks as in attached with this layout:
cgr
  • 4,423
  • 2
  • 24
  • 48
7
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
  • 779
  • 1
  • 11
  • 20
6
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,002
  • 11
  • 32
2
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
  • 237
  • 2
  • 6
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
  • 111
  • 1
  • 1
  • 9
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
  • 9
2
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 …
2
votes
1 answer

Gravity sensor listener not working

I want to get accelerometer sensor data which is in earth axis through a service. I read about a way to do it as well on one of the posts on stackoverflow. But I have an issue. @Override public void onSensorChanged(SensorEvent event) { …
2
votes
2 answers

What is the priority about gravity and layout_gravity in android?

I am testing LinearLayout and create a LinearLayout with 2 TextViews. the LinearLayout has the attribute gravity="center_vertical", and the first TextView within the LinearLayout has attribute layout_gravity="top". gravity="center_vertical" of…
karon
  • 21
  • 1
2
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
  • 700
  • 1
  • 7
  • 19
2
votes
3 answers

Align single item to center in RecyclerView android

Suppose I have one OR two items in RecyclerView . How could I display them in center RecyclerView must have width and height is match_parent AFAIK recyclerView starts from top. How could I give gravity = center to its single item. I mean if only 1…
AndroidGeek
  • 30,803
  • 14
  • 212
  • 262
1
2 3 4