【问题标题】:Keyboard and scrollviews键盘和滚动视图
【发布时间】:2015-05-16 10:46:24
【问题描述】:

我有一个带有表单的活动。我将所有视图放在ScrollView 中,因为当键盘打开时,我会滚动浏览这些字段。

当键盘打开时,第一个字段越过ScrollView 的顶部,变得无法访问。

这是布局:

<ScrollView 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">

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

    <EditText
        android:id="@+id/username"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="10dp"
        android:hint="Username"
        android:inputType="text|textEmailAddress"
        android:singleLine="true" />

    <EditText
        android:id="@+id/password"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="10dp"
        android:hint="Password"
        android:inputType="textPassword"
        android:singleLine="true" />

    <EditText
        android:id="@+id/password1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="10dp"
        android:hint="@string/repeat_password"
        android:inputType="textPassword"
        android:singleLine="true" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="10dp"
        android:orientation="horizontal">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:text="@string/gender" />

        <RadioGroup
            android:id="@+id/gender"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:paddingLeft="5dp">

            <RadioButton
                android:id="@+id/male"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:checked="true"
                android:text="M" />

            <RadioButton
                android:id="@+id/female"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="F" />
        </RadioGroup>
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="10dp"
        android:orientation="horizontal">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:text="@string/age" />

        <EditText
            android:id="@+id/age"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:ems="10"
            android:inputType="number"
            android:paddingLeft="5dp" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="10dp"
        android:orientation="horizontal">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:text="@string/education" />

        <Spinner
            android:id="@+id/education"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:paddingLeft="5dp" />
    </LinearLayout>

    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="10dp"
        android:onClick="salva"
        android:text="@string/save" />
</LinearLayout>

</ScrollView>

这是清单中的活动定义:

<activity
        android:name=".activities.SignUpActivity"
        android:configChanges="orientation|keyboardHidden|screenSize"
        android:label="@string/title_activity_sign_up">
</activity>

这是截图。用户名字段无法访问! (看右边的滚动条)

【问题讨论】:

  • android:windowSoftInputMode="stateHidden|adjustPan" 将此添加到您的清单活动部分
  • 这样视图不可滚动

标签: android keyboard scrollview android-scrollview


【解决方案1】:

在您的应用中使用以下内容清单

 android:windowSoftInputMode="stateHidden|adjustPan" 

更多详情,您可以访问这里

http://developer.android.com/guide/topics/manifest/activity-element.html

【讨论】:

【解决方案2】:

在您的活动清单条目中添加以下内容:

android:windowSoftInputMode="stateVisible|adjustPan".

【讨论】:

  • 这样视图不可滚动
【解决方案3】:

我找到了解决方案。问题是这一行:

android:layout_gravity="center"

我刚刚从布局文件中删除了它。清单是正确的。

【讨论】:

    猜你喜欢
    • 2017-06-15
    • 2014-08-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-11-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多