软输入平移视图但不足以显示完整的editText

时间:2011-06-30 19:33:30

标签: android android-edittext android-softkeyboard

我有一个有点复杂的布局,但最底层是一个巨大的EditText。当我点击它以使键盘打开时,所有内容都向上滑动,足以显示用户正在键入的位置(因为用户开始只键入1行是可见的,如果用户进入多行,那么它会更多显示2行等)。我希望所有内容都可以平移,以便整个EditText(所有空白区域)都可见。

<LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="@color/white"
        android:orientation="vertical">

        <EditText
            android:id="@+id/CommentBox"
            android:layout_width="fill_parent"
            android:layout_height="100dp"
            android:textSize="16sp"
            android:layout_marginLeft="6dp"
            android:layout_marginTop="4dp"
            android:background="@color/transparent"
            android:textColor="@color/gray"
            android:gravity="top"
            android:inputType="textMultiLine|textCapSentences|textShortMessage|textAutoCorrect|textNoSuggestions">
        </EditText>
    </LinearLayout>

现在已经挣扎了几天,不胜感激任何建议。

最好的说明方式是3张图片

这就是整个屏幕的样子

This is what the entire screen looks like

这就是现在的行为

This is what the behavior is right now

这是理想的行为

This is the desired behavior

希望这些图片能说明我的问题。我需要弄清楚如何实现这一目标。我能够强制视图平移到正确位置的唯一方法是将android:gravity设置为bottom,在这种情况下,文本写在底部。然而,这显然是一种非常奇怪的用户体验。我需要将文字放在普通文本框中。

1 个答案:

答案 0 :(得分:0)

能够破解模仿我所寻找的解决方案。 将布局放在scrollView中,将参数设置为adjustResize而不是adjustPan。然后单击editText

scrollView.postDelayed(new Runnable() { 
                public void run() { 
                    scrollView.scrollTo(0, scrollView.getBottom()); 
                } 
            } , 250); 

很想找到一种非黑客的做法,但这就是我所拥有的。