Development issue/problem:

Okay, first of all, I’ve looked all over the Internet, but no one has this kind of problem. So I just want 3 text views aligned at the bottom of the screen and the same width. Here’s a picture that represents what I want:

And this is my code:

Well, it works if the 3 textViews have the same height, but if their size is different, I get the following result:

The other strange behavior is that I get the following result when I set the layout_gravity of the largest text to center-vertical :

Of course I went crazy and tried other combinations with mid-verticals, but nothing worked the way I wanted it to at first:

Any advice on how to solve the problem?

How can I solve this problem?

Solution 1:

Correct answer

All other answers are wrong. Important points:

  1. You don’t need a RelativeLayout. You can do it with a layout.
  2. Your weights don’t have to be set to 1, you can just set them all to the same value (like 1).
  3. The most important thing you need is android:baselineAligned=false. In fact, I found this when looking at the source code of LinearLayout. It’s in the documentation, but it doesn’t mention that it’s turned on by default!

Anyway, here’s the code:

And from what I hear:

Good linear setup

Solution 2:

That’s all I’m saying. So I had the same problem, but with switch buttons instead of text display. For some reason, if one of the elements in LinearLayout (Horizontal) has a different height than the other views of the orbit and is set to the same gravity as the others, gravity is actually ignored.

I was able to get the desired behavior by wrapping each view in RelativeLayout and setting android: gravity to the relative layout instead of android: layout_gravity on each button. I also changed android: layout_weight button relative layout.

So instead of

Which gives the same problem as the one reported, I did this instead:

Solution 3:

**EDIT:

If that’s not all, add a background alignment flag as indicated by Timmmmm in one of the answers below. It’s the best way.

Use

A STATUE OF AN ASSHOLE:
Okay, I’ve edited it and added colors and gravity so that the text at the bottom has the same height and width, and I’ve raised the text at the bottom and in the middle of each view.

He has to do exactly what you asked him to do.

It uses LinearLayout within RelativeLayout, but sometimes we have to nest them together to get what we want. Add views to the relative layout and your texts will always be at the bottom, as long as the last child element in the relative layout is this linear layout, as shown above.

Solution 4:

Like Timm’s answer, but you can also use android:gravity=bottom for the attribute LinearLayout instead of android:layout_gravity=bottom for each TextView.

Here’s how:

Solution No 5:

If you don’t mind using RelativeLayout instead of Linear, I think it might work:

Solution No 6:

If you try to make all three child views the same height, change the height to 0, set android:weightSum or LinearLayout to 3, and android:layout_weight of each view to 1.

Solution No 7:

A much simpler solution would be to use the <space> tag:

Good luck!

android:gravity,linearlayout align bottom,linearlayout bottom,android place button at bottom of screen,layout_gravity not working in linearlayout,android align view to bottom of linearlayout,move view to bottom of linearlayout,bottom button in linearlayout,how to set button in bottom in linearlayout android

You May Also Like

Row-wise operations in R: compute row means in tidyverse

Everyone knows that the mean of a dataset is the sum of…

What is Bootrec Fixboot Access is Denied in Windows 10 & How to Fix it?

If you are having problems with accessing the Bootrec.exe command in Windows…

Looping Error on Android Emulator –

Development issue/problem: I can’t run my applications in the Android emulator because…

6 Reasons Why Your L1 Visa Is Getting Rejected

The L-1 visa is a non-immigrant visa issued by the United States…