2016年1月19日火曜日

TextInputLayout の中の EditText の baseline で揃える方法

「android:baselineAlignedChildIndex の振る舞い」で紹介した方法を使えば、TextInputLayout の中の EditText で位置を揃えることができます。
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     xmlns:app="http://schemas.android.com/apk/res-auto"  
  4.     android:layout_width="match_parent"  
  5.     android:layout_height="match_parent"  
  6.     android:orientation="horizontal"  
  7.     android:padding="16dp">  
  8.   
  9.     <TextView  
  10.         android:layout_width="wrap_content"  
  11.         android:layout_height="48dp"  
  12.         android:background="#ccccff"  
  13.         android:gravity="center_vertical"  
  14.         android:text="Cupcake" />  
  15.   
  16.     <android.support.design.widget.TextInputLayout  
  17.         android:id="@+id/input_layout"  
  18.         android:layout_width="match_parent"  
  19.         android:layout_height="wrap_content"  
  20.         android:layout_marginLeft="16dp"  
  21.         android:background="#ffcccc"  
  22.         android:baselineAlignedChildIndex="0"  
  23.         android:orientation="vertical"  
  24.         app:errorEnabled="true">  
  25.   
  26.         <EditText  
  27.             android:layout_width="match_parent"  
  28.             android:layout_height="wrap_content"  
  29.             android:hint="Donuts" />  
  30.   
  31.     </android.support.design.widget.TextInputLayout>  
  32.   
  33. </LinearLayout>  

0 件のコメント:

コメントを投稿