Android:软键盘将文本编辑移出屏幕
我正在尝试使用软键盘,以便用户可以输入他的信息,在我的android应用程序上创建一个新帐户。问题是我的一些文本编辑总是在屏幕外流动,用户看不到他实际键入的内容。屏幕如下所示:Android:软键盘将文本编辑移出屏幕,android,Android,我正在尝试使用软键盘,以便用户可以输入他的信息,在我的android应用程序上创建一个新帐户。问题是我的一些文本编辑总是在屏幕外流动,用户看不到他实际键入的内容。屏幕如下所示: <activity android:name=".activity.NewAccountActivity" android:label="@string/app_name" android:screenOrientation="portrait" android:windo
<activity android:name=".activity.NewAccountActivity"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:windowSoftInputMode="stateHidden|adjustResize" />
此屏幕是使用以下xml代码构建的:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:orientation="vertical"
android:layout_height="fill_parent">
<com.markupartist.android.widget.ActionBar
android:id="@+id/actionbar"
style="@style/ActionBar"/>
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1.0">
<LinearLayout
android:layout_gravity="bottom"
android:paddingTop="15dip"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<EditText android:id="@+id/txtPhoneNumber"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="15dip"
android:layout_marginRight="15dip"
android:nextFocusUp="@+id/LoginButton"
android:nextFocusDown="@+id/txtPassword"
android:hint="Phone Number"
android:inputType="number"
android:singleLine="true" />
<EditText android:id="@+id/txtPassword"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dip"
android:layout_marginLeft="15dip"
android:layout_marginRight="15dip"
android:hint="Password"
android:inputType="textPassword"
android:singleLine="true"
android:nextFocusDown="@+id/txtName"/>
<EditText android:id="@+id/txtName"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dip"
android:layout_marginLeft="15dip"
android:layout_marginRight="15dip"
android:hint="Name"
android:singleLine="true"
android:nextFocusDown="@+id/txtPin" />
<EditText android:id="@+id/txtPin"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dip"
android:layout_marginLeft="15dip"
android:layout_marginRight="15dip"
android:hint="Pin"
android:inputType="number"
android:singleLine="true" />
</LinearLayout>
</ScrollView>
<LinearLayout android:id="@+id/buttonsLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dip"
android:layout_marginLeft="15dip"
android:layout_marginRight="15dip" >
<Button android:id="@+id/btnLogin"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1.0"
android:text="@string/btnLogin"
android:onClick="onRegisterClick" />
</LinearLayout>
在我的AndroidManifest.xml中,我用以下方式定义了我的活动:
<activity android:name=".activity.NewAccountActivity"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:windowSoftInputMode="stateHidden|adjustResize" />
我尝试了不同的布局和WindowsOfInputMode组合,但我始终无法获得在屏幕上可见的文本编辑。我有什么遗漏吗
谢谢你的回复
T您的scrollview设置为填充父对象,这是否会导致控件垂直剪裁?如果要垂直拉伸,请将布局高度设置为0dip
您可能还想尝试在AndroidManifest.xml中替换活动的
windowSoftInputMode
,并将adjustResize
替换为adjustPan
,将此行添加到活动标记中
android:windowSoftInputMode="adjustPan"
像这样
<activity android:name=".activity.NewAccountActivity"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:windowSoftInputMode="stateHidden|adjustResize|adjustPan"/>
希望它能工作。您可以使用
adjustPan
将字段保持在屏幕上的可见区域内:
android:windowSoftInputMode="stateHidden|adjustPan"
更新: 尝试不要在
滚动视图
之外使用视图
。我已将您的布局更改为具有一个顶级滚动视图
和内部线性布局
。所有其他元件都位于线性布局
内。这是因为Android在调整软键盘屏幕时不知道如何正确滚动ScrollView
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true"
android:layout_weight="1.0" >
<LinearLayout
android:layout_gravity="bottom"
android:paddingTop="15dip"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<EditText android:id="@+id/txtPhoneNumber"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="15dip"
android:layout_marginRight="15dip"
android:nextFocusUp="@+id/LoginButton"
android:nextFocusDown="@+id/txtPassword"
android:hint="Phone Number"
android:inputType="number"
android:singleLine="true" />
<EditText android:id="@+id/txtPassword"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dip"
android:layout_marginLeft="15dip"
android:layout_marginRight="15dip"
android:hint="Password"
android:inputType="textPassword"
android:singleLine="true"
android:nextFocusDown="@+id/txtName"/>
<EditText android:id="@+id/txtName"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dip"
android:layout_marginLeft="15dip"
android:layout_marginRight="15dip"
android:hint="Name"
android:singleLine="true"
android:nextFocusDown="@+id/txtPin" />
<EditText android:id="@+id/txtPin"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dip"
android:layout_marginLeft="15dip"
android:layout_marginRight="15dip"
android:hint="Pin"
android:inputType="number"
android:singleLine="true" />
<LinearLayout android:id="@+id/buttonsLayout"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_marginTop="20dip"
android:layout_marginLeft="15dip"
android:layout_marginRight="15dip"
android:orientation="vertical">
<View
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1" />
<Button android:id="@+id/btnLogin"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="login"
android:onClick="onRegisterClick" />
</LinearLayout>
</LinearLayout>
</ScrollView>
这会导致软键盘显示在字段上,而不会向上滚动到键盘。我刚刚尝试过这个方法。同样,如果我将焦点设置为电话号码EditText,它就会离开屏幕,我看不到我正在输入的内容。谢谢你们,当我设置调整盘时,屏幕看起来是这样的。当焦点在最后一个exittext上时,键盘位于其上方。