Android ScrollView 中带有 EditText 的 TextInputLayout 隐藏焦点提示

Android TextInputLayout with EditText in ScrollView hides hint on focus

如果我将 EditText 聚焦在 ScrollView 中,就会发生这种情况(没关系):

然后,我聚焦下面的 EditText 并从图一重新聚焦 EditText,然后发生了这种情况:

提示未显示或显示错误(取决于滚动视图)。

部分解决方案: Scrollview 看到我想关注 EditText 而不是周围的 android.support.design.widget.TextInputLayout 元素。因此它不关心是否显示提示。

如何解决? 我的XML(基本上是一个带有一些线性布局的滚动视图,其中包含 android.support.design.widget.TextInputLayout 和 EditTexts):

<ScrollView
            android:layout_width="match_parent"
            android:fadeScrollbars="false"
            android:layout_height="wrap_content">

            <LinearLayout
                android:layout_width="match_parent"
                android:orientation="vertical"
                android:layout_height="match_parent">

                <LinearLayout
                    android:layout_width="match_parent"
                    android:orientation="horizontal"
                    android:focusable="true"
                    android:focusableInTouchMode="true"
                    android:weightSum="9"
                    android:descendantFocusability="beforeDescendants"
                    android:layout_height="match_parent">

                    <TextView
                        android:layout_width="0dp"
                        android:layout_weight="1"
                        android:text="1"
                        android:gravity="center"
                        android:layout_height="match_parent" />

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

                        <EditText
                            android:layout_width="match_parent"
                            android:layout_weight="1"
                            android:maxLines="1"
                            android:hint="hint1.1"
                            android:inputType="numberDecimal"
                            android:layout_height="match_parent" />

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

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

                        <EditText
                            android:layout_width="match_parent"
                            android:maxLines="1"
                            android:inputType="number"
                            android:hint="hint1.2"
                            android:layout_height="match_parent" />


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

                </LinearLayout>
                <LinearLayout
                    android:layout_width="match_parent"
                    android:orientation="horizontal"
                    android:weightSum="9"
                    android:layout_height="match_parent">

                    <TextView
                        android:layout_width="0dp"
                        android:layout_height="match_parent"
                        android:layout_weight="1"
                        android:text="2"
                        android:gravity="center"/>

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

                        <EditText
                            android:layout_width="match_parent"
                            android:layout_weight="1"
                            android:maxLines="1"
                            android:hint="hint2.1"
                            android:inputType="numberDecimal"
                            android:layout_height="match_parent" />

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

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

                        <EditText
                            android:layout_width="match_parent"
                            android:layout_weight="1"
                            android:maxLines="1"
                            android:hint="hint2.2"
                            android:inputType="number"
                            android:layout_height="match_parent" />

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

                </LinearLayout>
                <LinearLayout
                    android:layout_width="match_parent"
                    android:orientation="horizontal"
                    android:weightSum="9"
                    android:layout_height="match_parent">

                    <TextView
                        android:layout_width="0dp"
                        android:layout_height="match_parent"
                        android:layout_weight="1"
                        android:gravity="center"
                        android:text="3"/>

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

                        <EditText
                            android:layout_width="match_parent"
                            android:hint="hint3.1"
                            android:maxLines="1"
                            android:inputType="numberDecimal"
                            android:layout_height="match_parent" />

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

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

                        <EditText
                            android:layout_width="match_parent"
                            android:layout_weight="1"
                            android:hint="hint3.2"
                            android:maxLines="1"
                            android:inputType="number"
                            android:layout_height="match_parent" />

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

                </LinearLayout>

            </LinearLayout>

        </ScrollView>

使用此代码滚动到 edittext 视图的正确位置,

your_scrollview.post(new Runnable() { 
@Override
 public void run() { 
       your_scrollview.smoothScrollTo(0, your_EditBox.getBottom());
 } 
});