Android 水平布局中的TextInputLayout和2个ImageView
我正在尝试将一个TextInputLayout和两个ImageView以水平方向对齐在一个线性布局中。由于某些原因,我很难将它们定位在水平布局中。这就是我迄今为止所尝试的Android 水平布局中的TextInputLayout和2个ImageView,android,android-orientation,Android,Android Orientation,我正在尝试将一个TextInputLayout和两个ImageView以水平方向对齐在一个线性布局中。由于某些原因,我很难将它们定位在水平布局中。这就是我迄今为止所尝试的 <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:w
<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>
布局中有两个问题
首先,您的textinputtext
包含以下两个属性:
android:layout_width="0dp"
android:layout_weight="1"
这是使用layout\u weight
的普遍接受的模式,但weight仅在LinearLayout
的直接子级上有意义,并且由于此视图包装在TextInputLayout
中,因此此处不适用。将这些更改为:
android:layout_width="match_parent"
第二个问题是,您在线性布局
上指定了android:weightSum=“3.0”
,但其直接子项的权重总和仅为2.0
。将该属性的值更改为2.0
或将weightSum
attr一起删除(它实际上只会导致问题)。布局中有两个问题
首先,您的textinputtext
包含以下两个属性:
android:layout_width="0dp"
android:layout_weight="1"
这是使用layout\u weight
的普遍接受的模式,但weight仅在LinearLayout
的直接子级上有意义,并且由于此视图包装在TextInputLayout
中,因此此处不适用。将这些更改为:
android:layout_width="match_parent"
第二个问题是,您在线性布局
上指定了android:weightSum=“3.0”
,但其直接子项的权重总和仅为2.0
。要么将该属性的值更改为2.0
,要么完全删除weightSum
attr(这只会导致问题)。如果更改Textinput width会发生什么情况?@Brunofereira-编辑文本占据整个宽度。即使您设置了例如25dp的宽度?@如果我设置了它接受的宽度,但是它看起来太小了,提示被打断了。你也可以使用相对布局来实现水平布局,方法是分配不同的父级,并相应地将它们彼此对齐。如果更改Textinput width会发生什么情况?@BrunoFerreira-编辑文本占据整个宽度。如果你设置了例如25dp的宽度?@如果我设置了宽度,它会发生什么接受,但它看起来太小,提示被打断。您也可以使用相对布局来实现水平布局,方法是指定不同的父级并相应地将它们彼此对齐。非常感谢Ben!。现在看起来很不错!!最佳答案+1谢谢,本!。现在看起来很不错!!最佳答案+1