EditText 在键盘打开时将 TextView 移出屏幕 [英] EditText moves TextView out of the screen when they keyboard is opening
问题描述
我的布局底部有一个 EditText,顶部有一些 TextView.当我单击 EditText 时,它会从键盘上方的底部移动,这很好.但是 TextViews 也会向上移动并移出屏幕,因此您在再次关闭键盘之前无法看到它们.我怎样才能避免这种情况,但仍然在键盘上方有我的 EditText?我使用的是RelativeLayout.谢谢!
I have an EditText on the bottom of my layout und a few TextViews on the top. When I click on the EditText it moves from the bottom above the keyboard which is good. But the TextViews also move up and out of the screen so you can't see them until you close the keyboard again. How can I avoid this but still have my EditText above the keyboard? I'm using a RelativeLayout. Thanks!
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.ncss.tyfby.Feeling"
android:background="#1baa84">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true">
<TextView
android:text="I am"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="@+id/IamTV"
android:layout_weight="0.10"
android:textSize="40sp"
android:textStyle="normal|bold"
android:gravity="bottom" />
<EditText
android:layout_width="wrap_content"
android:inputType="textPersonName"
android:ems="10"
android:id="@+id/iamAdjective"
android:background="@android:drawable/editbox_background_normal"
android:hint="powerful"
android:layout_height="match_parent"
android:layout_weight="1"
android:layout_marginLeft="10dp" />
<ImageButton
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="@+id/send"
android:layout_weight="0.10"
android:src="@android:drawable/ic_menu_send"
android:background="@drawable/transparent"
android:onClick="send"
android:layout_marginLeft="5dp" />
</LinearLayout>
<TextView
android:text="I am"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/iam1"
android:textSize="18sp" />
<TextView
android:text="I am"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/iam2"
android:textSize="18sp"
android:layout_below="@+id/iam1"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="10dp" />
<TextView
android:text="I am"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/iam4"
android:textSize="18sp"
android:layout_below="@+id/iam3"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="10dp" />
<TextView
android:text="I am"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/iam5"
android:textSize="18sp"
android:layout_below="@+id/iam4"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="10dp" />
<TextView
android:text="I am"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/iam3"
android:textSize="18sp"
android:layout_below="@+id/iam2"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="10dp" />
推荐答案
您可以探索 windowSoftInputMode
,您可以在 AndroidManifest.xml 文件中为您的活动配置:活动 |Android 开发者.
You may explore windowSoftInputMode
that you can configure for your Activity in the AndroidManifest.xml file: activity | Android Developers.
也许 windowSoftInputMode="adjustResize"
可能对您有用.
Perhaps windowSoftInputMode="adjustResize"
might be useful for you.
除此之外,您还需要将布局 XML 更改为:
In addition to that you will need to change your layout XML to something like:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_height="match_parent"
android:layout_width="match_parent"
tools:context="com.ncss.tyfby.Feeling"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:orientation="vertical"
android:background="#1baa84">
<ScrollView
android:layout_height="match_parent"
android:layout_width="wrap_content"
android:layout_weight="1">
<LinearLayout
android:layout_height="match_parent"
android:layout_width="wrap_content"
android:orientation="vertical">
<TextView
android:text="I am"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/iam1"
android:textSize="18sp" />
<TextView
android:text="I am"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/iam2"
android:textSize="18sp"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="10dp" />
<TextView
android:text="I am"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/iam4"
android:textSize="18sp"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="10dp" />
<TextView
android:text="I am"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/iam5"
android:textSize="18sp"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="10dp" />
<TextView
android:text="I am"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/iam3"
android:textSize="18sp"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="10dp" />
</LinearLayout>
</ScrollView>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true">
<TextView
android:text="I am"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="@+id/IamTV"
android:layout_weight="0.10"
android:textSize="40sp"
android:textStyle="normal|bold"
android:gravity="bottom" />
<EditText
android:layout_width="wrap_content"
android:inputType="textPersonName"
android:ems="10"
android:id="@+id/iamAdjective"
android:background="@android:drawable/editbox_background_normal"
android:hint="powerful"
android:layout_height="match_parent"
android:layout_weight="1"
android:layout_marginLeft="10dp" />
<ImageButton
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="@+id/send"
android:layout_weight="0.10"
android:src="@android:drawable/ic_menu_send"
android:background="@drawable/transparent"
android:onClick="send"
android:layout_marginLeft="5dp" />
</LinearLayout>
</LinearLayout>
这篇关于EditText 在键盘打开时将 TextView 移出屏幕的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!