2017-02-14 7 views
0

の描画可能左:これを行うにはenter image description hereポジショニングTextInputLayout

提案の方法は、EditText,drawableLeftを追加することですが、EditTextアンダーバーはずっと引き出し可能下回っ拡張します。

もう1つの方法は、TextInputLayoutの左側にImageViewを作成することです。この問題は、のエラーメッセージが表示されているかどうかに応じて余分な高さを切り替えるため、アイコンをEditTextと正確に揃えておくことが難しくなります。これには、TextInputLayoutのエラーメッセージビューの高さを計算し、エラーメッセージが表示されているかどうかを確認するためにアイコンの下にプレースホルダを配置する必要があります。

TextInputLayoutでこのデザインを達成する良い方法はありますか?

答えて

0

この作品は私にとっては、そのすべてを水平方向のLinearLayoutに入れています。

<LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:orientation="horizontal"> 
      <ImageView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_gravity="center_vertical" 
       android:src="@drawable/ic_user_login_dark"/> 

      <android.support.design.widget.TextInputLayout 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_marginLeft="32dp" 
       android:id="@+id/username"> 

       <EditText 

        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:hint="@string/hint_username" 
        android:inputType="textPersonName" /> 

      </android.support.design.widget.TextInputLayout> 

     </LinearLayout>