我想把TextInputLayout
和Spinner
放在一行。另外,我需要在TextInputLayout
上显示错误。它在使用Android 6.1+的设备上运行良好(我使用6.1+在Sony上进行了测试,在使用8.0的模拟器上进行了测试)。但在我的搭载Android 5.1的Samsung上,它看起来像这样:
编辑器中的布局
使用Android 6.1 +
的设备上的布局
三星的布局错误
我还为Layout(LinearLayout,TextInputLayout,EditText,Spinner)中的元素设置了不同的背景。元素的大小和位置似乎是正确的。看起来像promblem是三星的Spinner刚刚绘制线低于预期
彩色布局实验
我的xml代码:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="18dp"
tools:context="com.app.MyActivity" >
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="-10dp">
<android.support.design.widget.TextInputLayout
android:id="@+id/layout_new_amount"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
app:errorEnabled="true"
app:hintEnabled="false">
<EditText
android:id="@+id/edit_new_amount"
android:layout_width="match_parent"
android:layout_height="46dp"
android:ems="10"
android:hint="@string/hint_amount"
android:inputType="number|numberDecimal"
android:singleLine="true" />
</android.support.design.widget.TextInputLayout>
<Spinner
android:id="@+id/spinner_currency"
style="@style/Base.Widget.AppCompat.Spinner.Underlined"
android:layout_width="98dp"
android:layout_height="46dp"
android:spinnerMode="dialog"/>
</LinearLayout>
</LinearLayout>
如何解决?这是Android 5.1或samsung固件的错误吗?
答案 0 :(得分:0)
1)现在将重力应用于衬里布局&#34;开始|中心&#34;
答案 1 :(得分:0)
一个库提供了在所有设备中维护布局大小的功能。您可以使用它。 在app level gradle文件中添加以下依赖项..
implementation 'com.intuit.sdp:sdp-android:1.0.4'
然后以这种格式定义大小,如..
android:layout_width="@dimen/_50sdp"
android:layout_height="@dimen/_50sdp"
android:padding="@dimen/_5sdp"