【问题标题】:Two TextInputLayout in the same line同一行中的两个 TextInputLayout
【发布时间】:2017-01-15 09:08:27
【问题描述】:

如何在同一行中使用两个TextInputLayout(Material Design),即水平,这样它们必须平等地获得线性布局中的所有水平空间。我试过线性布局

           <android.support.design.widget.TextInputLayout
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_weight="0.5">

                    <EditText
                        android:id="@+id/firstname"
                        android:layout_width="0dp"
                        android:layout_height="match_parent"
                        android:layout_weight="0.5"
                        android:hint="@string/fhint"
                        android:inputType="textPersonName"
                        android:maxLength="20"
                        android:maxLines="1"
                        android:elevation="6dp"
                        android:singleLine="true" />

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

                <android.support.design.widget.TextInputLayout
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_weight="0.5">

                    <EditText
                        android:id="@+id/lastname"
                        android:layout_width="0dp"
                        android:layout_height="match_parent"
                        android:layout_weight="0.5"
                        android:hint="@string/lhint"
                        android:inputType="textPersonName"
                        android:elevation="6dp"
                        android:maxLines="1"
                        android:maxLength="15"
                        android:singleLine="true" />

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

            </LinearLayout>

【问题讨论】:

    标签: android material-design


    【解决方案1】:

    仅应在 TextInputLayout 中设置权重,将其从 EditTexts 中删除

       <android.support.design.widget.TextInputLayout
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="0.5">
    
                <EditText
                    android:id="@+id/firstname"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:hint="@string/fhint"
                    android:inputType="textPersonName"
                    android:maxLength="20"
                    android:maxLines="1"
                    android:elevation="6dp"
                    android:singleLine="true" />
    
            </android.support.design.widget.TextInputLayout>
    
            <android.support.design.widget.TextInputLayout
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="0.5">
    
                <EditText
                    android:id="@+id/lastname"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:hint="@string/lhint"
                    android:inputType="textPersonName"
                    android:elevation="6dp"
                    android:maxLines="1"
                    android:maxLength="15"
                    android:singleLine="true" />
    
            </android.support.design.widget.TextInputLayout>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-03-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-12-01
      • 2012-05-14
      • 1970-01-01
      相关资源
      最近更新 更多