在Horizo​​ntalScrollView上聚焦EditText会导致ScrollView隐藏EditText

Smi*_*ith 2 android scroll horizontalscrollview android-edittext

我有一个水平滚动视图占据了屏幕的右半部分.在它上面,我有一个EditText.当我选择EditText来编辑文本时,Horizo​​ntalScrollView会向右滚动.我猜它正在尝试将EditText放在最左边的位置.无论如何,由于Horizo​​ntalScrollView占据了屏幕的右侧,通过这样做,我再也看不到EditText,因为它现在被我放在屏幕左侧的内容所掩盖.当我专注于布局内的某些内容时,如何防止Horizo​​ntalScrollView自动滚动?

谢谢.非常感激.

HALP

编辑:发布代码.我实际上是基于生成的信息创建我的EditText,所以这不是它实际上的样子,但它应该捕获ideai.

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <View
        android:layout_leftOf="@+id/Anchor"/>


    <View
        android:id="@+id/Anchor"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_centerHorizontal="true"
        android:background="#000" />

    <ScrollView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_rightOf="@+id/Anchor"
            android:fillViewport="true" >

            <HorizontalScrollView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:fillViewport="true" >

                <TableLayout
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:padding="10dp" >

                  <TableRow>
                     <EditText>

                     ABOVE is the view that is going to the left

                     MOre views which would cause Scrolling to the right

                  </TableRow>
                </TableLayout>

            </HorizontalScrollView>
        </ScrollView>

</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

Osw*_*eon 5

如果使用android:gravity ="center"删除它,请在XML中使用EditText

  • 精彩的回答从未想过这会解决我的问题 (2认同)