まず、以下のようなレイアウトがあった場合
- <?xml version="1.0" encoding="utf-8"?>
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:orientation="horizontal">
- <TextView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:background="#ccccff"
- android:paddingTop="60dp"
- android:text="Cupcake" />
- <LinearLayout
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_marginLeft="10dp"
- android:layout_marginRight="10dp"
- android:background="#ffcccc"
- android:orientation="vertical">
- <TextView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="Donuts" />
- <TextView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="Eclare" />
- </LinearLayout>
- </LinearLayout>

LinearLayout はデフォルトで android:baselineAligned="true" がセットされているので、子ビューの LinearLayout に android:baselineAlignedChildIndex="0" を指定すると次ようなレイアウトに変わります。
- <?xml version="1.0" encoding="utf-8"?>
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- ...>
- <TextView
- ... />
- <LinearLayout
- ...
- android:baselineAlignedChildIndex="0">
- ....
- </LinearLayout>
- </LinearLayout>

android:baselineAlignedChildIndex="1" を指定すると次のようになります。

0 件のコメント:
コメントを投稿