1

I had the xml as shown below, but dit why the second TextView not align to the top of the LinearLayout?

<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="40dp"
    android:orientation="horizontal"
    android:background="@color/colorAccent">
    <TextView
        android:id="@+id/tv_1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="16dp"
        android:text="AAAA"/>
    <TextView
        android:id="@+id/tv_2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="9dp"
        android:text="BBBB"/>
</LinearLayout>

and the result is

The TextView with id "tv_2" did not align to the LinearLayout and seems like had several pixes space, I'll be very appreciate that anyone can tell me the reason.

DaFois
  • 2,197
  • 8
  • 26
  • 43
taibai
  • 11
  • 1
  • 1
    You'll need to set `android:baselineAligned="false"` on the ``. By default, a horizontal `LinearLayout` will align the baselines of the first line of text in each `TextView` child. In your case, the second, shorter `TextView` is being shifted down, so its baseline lines up with the first's. – Mike M. Nov 10 '18 at 09:28
  • 1
    I tried it and it did work.Thank you very much!! – taibai Nov 10 '18 at 10:29

0 Answers0