Android 滚动包含编辑文本的滚动视图
我的滚动视图包含一个线性布局,其中还包含一些编辑文本字段。现在,当我点击底部的编辑文本字段时,软键盘出现了,但我的问题是它覆盖了编辑文本字段。这是我在android清单文件中声明的活动:Android 滚动包含编辑文本的滚动视图,android,scroll,android-edittext,scrollview,Android,Scroll,Android Edittext,Scrollview,我的滚动视图包含一个线性布局,其中还包含一些编辑文本字段。现在,当我点击底部的编辑文本字段时,软键盘出现了,但我的问题是它覆盖了编辑文本字段。这是我在android清单文件中声明的活动: 这是我的layout.xml文件,用于此活动 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" androi
这是我的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编程非常陌生。我无法解决此问题,并且无法找到在不调整主窗口大小的情况下滚动我的滚动视图的方法。我只想在出现软键盘时滚动我的滚动视图。请提前更改
您可以使用您的ScrollView.scrollTo(int x,int y)或您的ScrollView.smoothScrollTo(int x,int y)将滚动视图移动到适当的坐标,以便同时显示编辑文本框和键盘 有关这些函数和其他scrollview函数的更多信息,请参见您可以尝试:
ScrollView scroll = (ScrollView)findViewById(R.id.scrollview);
scroll.scrollTo(0, sv.getBottom());
或
这两个先前指出的解决方案都可以奏效。但是,如果edittext位于ListView的底部,屏幕键盘仍会覆盖它,则可能仍然存在问题。不确定是否可以将scrollview滚动到没有更多内容的位置 我看到的是,您可能会在清单中使用两个相互矛盾的标志:
android:windowSoftInputMode="stateHidden|adjustResize|adjustPan" > </activity>
android:WindowsOfInputMode=“stateHidden | adjustResize | adjustPan”>
adjustResize和adjustPan不能组合使用。只需调整大小即可尝试它的外观。这应该可以避免键盘覆盖了您的任何视图。嗨,MCWhitaker,thanx,请快速回复,但这没有帮助,也不能解决我的问题。嗯,看看atla的解决方案,坦白地说,如果它按预期工作,结果将更加优雅。如果这不起作用(这是一个非常难看的解决方案),您可以在edittext下面有不可见的视图,并在单击edittext然后移动scrollview时将其设置为可见。就像我说的,丑陋,但这肯定能完成任务。Thanx Riandy,但这也不能解决我的问题。嗨,Atla,Thanx,谢谢你的回答。最后它对我起了作用。非常感谢你。
android:windowSoftInputMode="stateHidden|adjustResize|adjustPan" > </activity>