2

我的滚动视图包含一个线性布局,其中还包含一些编辑文本字段。现在,当我单击底部的编辑文本字段时,会出现软键盘,但我的问题是它覆盖了该编辑文本字段。这是我在 android 清单文件中声明的活动:

<activity android:name="me.example.scrollview.LoginActivity" android:label="@string/title_activity_login" android:theme="@android:style/Theme.Black.NoTitleBar" android:windowSoftInputMode="stateHidden|adjustResize|adjustPan" > </activity>

这是我用于此活动的 layout.xml 文件。

<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"
android:background="@android:color/darker_gray"
tools:context=".LoginActivity" >

<ScrollView
    android:id="@+id/login_sv_login_container"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:isScrollContainer="true"
    android:background="@android:color/transparent" >

    <LinearLayout
        android:id="@+id/login_ll_container"
        android:layout_width="250dp"
        android:layout_height="wrap_content"
        android:layout_marginTop="230dp"
        android:layout_gravity="center_horizontal"
        android:background="@android:color/transparent"
        android:orientation="vertical" >

        <EditText
            android:id="@+id/txt_username"
            android:layout_width="match_parent"
            android:layout_height="40dp"
            android:layout_gravity="center_horizontal"
            android:background="@drawable/rounded_edittext"
            android:ems="10"
            android:inputType="textEmailAddress"
            android:maxLines="1"
            android:singleLine="true" >

            <requestFocus />
        </EditText>

        <EditText
            android:id="@+id/txt_phone"
            android:layout_width="match_parent"
            android:layout_height="40dp"
            android:layout_marginTop="10dp"
            android:background="@drawable/rounded_edittext"
            android:ems="10"
            android:inputType="phone"
            android:maxLines="1"
            android:singleLine="true" />

        <EditText
            android:id="@+id/txt_password"
            android:layout_width="match_parent"
            android:layout_height="40dp"
            android:layout_marginTop="10dp"
            android:background="@drawable/rounded_edittext"
            android:ems="10"
            android:inputType="textPassword"
            android:maxLines="1"
            android:singleLine="true" />

        <Button
            android:id="@+id/btn_login"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="right"
            android:layout_marginTop="10dp"
            android:background="@drawable/ic_login"
            android:text="" />
    </LinearLayout>
</ScrollView>

现在请帮助我,因为我对 android 编程很陌生。我无法解决这个问题,并且在不调整主窗口大小的情况下找不到滚动视图的方法。我只希望我的滚动视图在软键盘出现时进行滚动。提前谢谢。

在此处输入图像描述

4

3 回答 3

0

您可以使用 YOURSCROLLVIEW.scrollTo(int x, int y) 或 YOURSCROLLVIEW.smoothScrollTo(int x, int y) 将滚动视图移动到适当的坐标,以便同时显示编辑文本框和键盘。

有关这些功能和其他滚动视图功能的更多信息可以在 android 开发者参考页面上找到。

于 2013-07-15T12:02:11.407 回答
0

你可以试试:

ScrollView scroll = (ScrollView)findViewById(R.id.scrollview);
scroll.scrollTo(0, sv.getBottom());

或者

scroll.scrollTo(5, 10);
于 2013-07-15T12:05:06.310 回答
0

之前指出的两种解决方案都可以工作。但是,如果编辑文本位于 ListView 的底部,屏幕键盘仍会覆盖它,则可能仍然存在问题。不确定滚动视图是否可以滚动到没有更多内容的点。

我所看到的是,您可能会在清单中使用两个相互矛盾的标志:

android:windowSoftInputMode="stateHidden|adjustResize|adjustPan" > </activity>

恕我直言,adjustResize 和 adjustPan 不能组合。尝试仅使用 adjustResize 的外观。这应该避免键盘覆盖您的视野。

于 2013-07-15T12:13:10.310 回答