Questions tagged [layout-gravity]

Android layout parameter that sets the gravity (alignment) of a View or Layout inside its parent container.

Standard gravity constant that a child supplies to its parent. Defines how the child view should be positioned, on both the X and Y axes, within its enclosing layout.

Must be one or more (separated by |) of the allowed constant values.

146 questions
5
votes
2 answers

How to set both gravity and layout gravity of a LinearLayout programatically

I am risking writing a duplicate question, but as I was researching the answer to another SO question, I realized that I couldn't find a simple question and answer that included setting both gravity and layout_gravity of a LinearLayout. Also, I was…
Suragch
  • 484,302
  • 314
  • 1,365
  • 1,393
5
votes
3 answers

Setting center gravity of child view change layout alignment of another child view in horizontal layout?

In my horizontal LinearLayout, I set the gravity in one view to be center_vertical, and then I tried to set layout_gravity for a second view, but that view is lined up with the centered text in the first view!
Lou Morda
  • 5,078
  • 2
  • 44
  • 49
5
votes
3 answers

how to align an element to right in horizontal LinearLayout?

I have a LinearLayout that contains a lot of TextViews and ImageButtons, I want to align some of these elements to right, i had a look at this and this but i can't use their tips as i can't change the orientation and can't make android.gravity:right…
4
votes
1 answer

android: how to change property of layout_gravity of a row_item in a listview

I'm trying to implement a chat bubbles that can appear to the left or the right. I read a lot of answers already published here but i didn't manage to get any of them working for me, maybe i'm missing something. if i change the layout_gravity of the…
Tomer
  • 255
  • 2
  • 9
4
votes
5 answers
4
votes
1 answer

how to center relative layout in linearlayout

I want to center horizontally and vertically block L3 on this image, can you help me with the layout structure to use. ON the right side is current structure of the menu. Thanks. Here is the layout.xml code:
yozhik
  • 4,644
  • 14
  • 65
  • 98
4
votes
2 answers

Place a block at the center of a ScrollView

I have a ScrollView that contains a single child (elements wrapped by a LinearLayout). Sometime this child's height is half of the viewport's height, sometime it is bigger. Here the layout :
Jerec TheSith
  • 1,932
  • 4
  • 32
  • 41
4
votes
4 answers

Android: layout_gravity center does not center

I have a problem, that is maybe silly, but I just can't figure out why this is not working. Basically, I have a header in my activity. This header should be centered. Layout-XML
Valentino Ru
  • 4,964
  • 12
  • 43
  • 78
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
2 answers

Set layout gravity from integers resource file

Gravity value must be stored in a resource file because I have a multi-language app. (Arabic/English) which will affect the layout direction from ltr to rtl. I used to do the same approach with eclipse adt successfully. Error says: Cannot resolve…
hasan
  • 23,815
  • 10
  • 63
  • 101
3
votes
2 answers

Android: Difference between setTextAlignment and setGravity

I'm working with an EditText, and know that setTextAlignment was not implemented until API 17, but don't see how using setTextAlignment is any easier or better than setGravity. Which should I use for what purposes, or does it not matter? I find…
3
votes
1 answer

android:gravity - bottom vs. end. What's the difference?

what is the difference between 'bottom' and 'end' constants of the android:gravity attribute? I am aware of the official documentation here but I am not sure what the actual implications…
Egis
  • 879
  • 2
  • 9
  • 13
2
votes
4 answers

Adjust TextView to Vertically center in LinearLayout (horizental)

I have four TextView in LinearLayout with orientation="horizontal". Below in image, I want my fourth TextView to vertically center with respect to other views, In simple words, I want to move my fourth TextView a little bit up so it looks like in…
Shoaib Kakal
  • 1,090
  • 2
  • 16
  • 32
2
votes
4 answers

layout_gravity doesn't work with Horizontal orientation in LinearLayout

I want to align text and an image in a LinearLayout in the same line. I thought of using layout_gravity option for the TextView and ImageView within a LinearLayout with orientation=horizontal but it doesn't seem to work. Any reason why is that?…
Neelabh
  • 31
  • 6
2
votes
3 answers

android:layout_gravity="end" not working when compiling in a real device

I am trying to align a balloon message to the right/end of the screen, and despite showing it at the right, when seeing in a device, it is to the left.
user4383363
1
2
3
9 10