0

I have a simple LinearLayout and I try to make it looks like this: look2

Instead it looks like: look1

My xml is:

<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="horizontal">
    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:orientation="vertical"
        >
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="miasto"
            android:textSize="10sp"/>
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:text="ulica"
            android:textSize="15sp"           
            android:gravity="bottom"
            />
    </LinearLayout>
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:textSize="30sp"
        android:text="22"
        android:gravity="bottom"/>

</LinearLayout>

Why gravity="bottom" doesn't work?

Daniel Więcek
  • 625
  • 1
  • 10
  • 16
  • 1
    The answer is here: https://stackoverflow.com/questions/4768738/android-textview-remove-spacing-and-padding-on-top-and-bottom – Daniel Więcek Sep 02 '17 at 19:58

2 Answers2

0

You set this text view a width of wrap_content it means, what ever the text is, the view take the size of the text and for LinearLayout , the default gravity is center

Thus, Change

android:layout_height="wrap_content"

to

android:layout_height="match_parent"

Meanwhile, just for your information, gravity is the way the text will align itself in the TextView. The TextView being in wrap_content does nothing, as the TextView is exactly the size of the text.

layout_gravity is the way the TextView will align itself in its parent, in your case in the LinearLayout.

Lal
  • 14,726
  • 4
  • 45
  • 70
  • Am I missing something? The TextView on the right has match_parent height. And I know the difference between layout gravity and gravity. If text_size is the same - both bottom textviews are int th same line, but if not... – Daniel Więcek Sep 02 '17 at 19:26
  • That is because you have `android:layout_height="wrap_content"` for the `LinearLayout`. Change that to `match_parent` and see if it works.. – Lal Sep 02 '17 at 19:29
  • I know something about Android and I spent few hours trying to understand this. Of course I've tested many configurations. None of them is working. Please paste working code if you have some. – Daniel Więcek Sep 02 '17 at 19:40
-1

Try to make your textview height match_parent.

Chirag Gohil
  • 352
  • 1
  • 2
  • 14