我有表格的活动。我将所有视图都放在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>
这是截图。用户名字段无法访问! (看右边的滚动条)
答案 0 :(得分:1)
在您的应用清单
中使用以下内容 android:windowSoftInputMode="stateHidden|adjustPan"
有关详细信息,请访问此处
http://developer.android.com/guide/topics/manifest/activity-element.html
答案 1 :(得分:0)
在您的活动清单条目中添加以下内容:
android:windowSoftInputMode="stateVisible|adjustPan"
。
答案 2 :(得分:0)
我找到了解决方案。问题是这一行:
android:layout_gravity="center"
我刚从布局文件中删除了它。清单是正确的。