2017-08-03 10 views
0

TextInputLayoutと2つのimageViewをリニアレイアウトで水平方向に揃えようとしています。何らかの理由で、私は水平レイアウトで配置するのが難しいです。これはこれまで私が試したことです。TextInputLayoutと2つのイメージビューが水平レイアウトになっています

<LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal" 
     android:weightSum="3.0"> 

     <android.support.design.widget.TextInputLayout 
      android:id="@+id/longDescriptionTextInputLayout" 
      style="@style/textfieldbox" 
      app:hintTextAppearance="@style/TextAppearence.App.TextInputLayout" 
      android:layout_width="0dp" 
      android:layout_weight="1" 
      android:layout_height="wrap_content" 
      android:layout_marginTop="20dp"> 

     <android.support.design.widget.TextInputEditText 
      android:id="@+id/longDescriptionTextInputEditText" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:background="@null" 
      android:layout_weight="1" 
      android:drawablePadding="15dp" 
      android:textColor="@color/textInputEditTextColor" 
      android:drawableStart="@drawable/ic_attach_file_black_24dp" 
      android:drawableTint="@color/Gallery" 
      android:hint="@string/longDesc" 
      android:inputType="textEmailAddress" 
      tools:ignore="MissingPrefix,UnusedAttribute" /> 

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

     <ImageView 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="0.5" 
      android:src="@drawable/ic_mic_black_24dp" /> 

     <ImageView 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="0.5" 
      android:src="@drawable/ic_volume_up_black_48dp"/> 

    </LinearLayout> 

私が間違っていることを理解できません。どんな助けもありがとうございます。出力画像を添付する。先頭の空白はTextInputEditTextです。

Final Result

+0

Textinputの幅を変更するとどうなりますか? –

+0

@BrunoFerreira - EditTextは幅全体を占有します。 –

+0

幅25dpの例を設定している場合は? –

答えて

1

あなたのレイアウトの2つの問題があります。

最初は、あなたのTextInputEditTextは、これら2つの属性が含まれていることである。

 android:layout_width="0dp" 
     android:layout_weight="1" 

これはlayout_weightを使用するため、一般的に受け入れられた模様ですが、重量はわずかLinearLayoutの直接の子に理にかなっており、このビューがあるので、 TextInputLayoutで包まれていますが、ここでは適切ではありません。それらの変更:

 android:layout_width="match_parent" 

を第二の問題は、あなたがあなたのLinearLayoutandroid:weightSum="3.0"を指定しているということですが、その直接の子だけ2.0まで追加の重みを持っています。その属性の値を2.0に変更するか、weightSum attrを完全に削除してください(本当に問題が発生するだけです)。

+0

ありがとう、ベン!それは今かなり可愛いよ!ベストアンサー+1 –

関連する問題