【问题标题】:Wrong alignment of TextInputLayout and SpinnerTextInputLayout 和 Spinner 对齐错误
【发布时间】:2018-10-01 17:52:19
【问题描述】:

我想把TextInputLayoutSpinner 放在一行。另外,我需要在TextInputLayout 上显示错误。它在 `Android 6.1+ 的设备上运行良好(我在 6.1+ 的索尼和 8.0 的模拟器上测试了它)。但是在我的带有 Android 5.1 的三星上,它看起来像这样:

编辑器中的布局

Android 6.1+ 设备上的布局

三星的布局错误

我还为 Layout 中的元素设置了不同的背景(LinearLayout、TextInputLayout、EditText、Spinner)。元素的大小和位置似乎是正确的。看起来问题是三星上的 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>

如何解决?这是安卓5.1还是三星固件的bug?

【问题讨论】:

    标签: android android-spinner android-textinputlayout android-5.1.1-lollipop samsung-galaxy


    【解决方案1】:

    1) 现在将重力应用到衬垫布局“开始|中心”

    【讨论】:

      【解决方案2】:

      一个库提供了在所有设备中保持布局大小的功能。您可以使用它。 在应用级 gradle 文件中添加以下依赖项..

       implementation 'com.intuit.sdp:sdp-android:1.0.4'
      

      然后以这种格式定义大小,如..

              android:layout_width="@dimen/_50sdp"
          android:layout_height="@dimen/_50sdp"
          android:padding="@dimen/_5sdp"
      

      【讨论】:

        猜你喜欢
        • 2017-02-19
        • 1970-01-01
        • 1970-01-01
        • 2012-11-02
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多