问题描述
我对 Android 开发非常陌生,我在线性布局下有几个元素。我加了
any[listA] if list_A != None then None
在我的清单文件下。但是,只有部分屏幕可以调整。底部滚动布局不可调,软键盘出现时,名字和姓氏TextView不会调整。我想知道是不是我的 XML 文件的布局有问题。
有什么想法吗?请帮忙!谢谢!
android:windowSoftInputMode="adjustResize"
解决方法
-
首先,布局的属性比较杂乱,涉及到不同的
ViewGroup
,比如你加了constraint,没有ConstrainLayout,也加了RelativeLayout
的属性,但是有是你的。 -
其次,就手机屏幕尺寸而言,填充/边距值太大了……比如
400dp
。所以这也需要修复。 -
您询问的最初问题是
这样的环绕滚动视图EditText
位于软键盘后面。并且为了在软键盘打开时保持它们显示;应该有一些滚动视图。因此,要解决此问题,您需要一个像ScrollView
这里针对上面提到的三个点进行了下面的布局
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<EditText
android:id="@+id/firstNamEdt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:ems="10"
android:hint="First Name"
android:inputType="textPersonName" />
<EditText
android:id="@+id/lastNameEdt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:ems="10"
android:hint="Last Name"
android:inputType="textPersonName" />
<EditText
android:id="@+id/emailEdt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:ems="10"
android:hint="Email"
android:inputType="textPersonName" />
<Button
android:id="@+id/crtBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Register" />
<ScrollView
android:id="@+id/scrollView2"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TableLayout
android:id="@+id/tableLayout"
android:layout_width="412dp"
android:layout_height="wrap_content"
android:overScrollMode="always"
android:scrollbarStyle="insideInset"
android:scrollbars="vertical">
<TableRow
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center">
<TextView
android:id="@+id/firstNameRow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true"
android:gravity="center"
android:padding="10dp"
android:text="First Name"
android:textColor="@color/black" />
<TextView
android:id="@+id/lastNameRow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:padding="10dp"
android:scrollbars="vertical"
android:text="Last Name"
android:textColor="@color/black" />
</TableRow>
</TableLayout>
</LinearLayout>
</ScrollView>
</LinearLayout>
</ScrollView>
这对我有用,但如果您仍有问题,可以尝试添加:
在清单文件中:在承载此布局的活动中添加 android:windowSoftInputMode="adjustResize"
。