我正在尝试调整尺寸以适合出现键盘时的屏幕大小,我按照此处提供的说明进行操作:How to adjust layout when soft keyboard appears
但是似乎仍然无法正常工作,唯一上升的文字是“ Welcome to ....”,如果您降低我的输入框(用户名,密码,电子邮件,全名),以便当键盘出现时隐藏起来,因此即使“欢迎...”上移也不会发生任何事情。
我不知道问题可能出在这里,这是我的活动布局:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView 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_width="match_parent"
android:fillViewport="true"
android:layout_height="match_parent"
android:background="#000000"
tools:context=".testLayout">
<RelativeLayout
android:id="@+id/mainLayout"
android:layout_width="match_parent"
android:gravity="center"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/logoLayout"
>
<ImageView
android:layout_width="140dp"
android:layout_height="35dp"
android:layout_marginTop="10dp"
android:layout_marginStart="10dp"
android:background="@drawable/nlogo">
</ImageView>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:id="@+id/logoLayout1"
android:layout_below="@id/logoLayout"
>
<EditText
android:id="@+id/testUsernameText"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginStart="50dp"
android:layout_marginTop="48dp"
android:layout_marginEnd="50dp"
android:background="@drawable/rounded_background"
android:gravity="center_vertical"
android:hint="Username"
android:paddingStart="10dp"
android:text=""
android:textColor="@color/white"
android:textColorHint="@color/hint_color"
android:textCursorDrawable="@null"
android:textSize="18sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/imageView2" />
<EditText
android:id="@+id/testPasswordText"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginStart="50dp"
android:layout_marginTop="10dp"
android:layout_marginEnd="50dp"
android:background="@drawable/rounded_background"
android:gravity="center_vertical"
android:hint="Password"
android:paddingStart="10dp"
android:text=""
android:textColor="@color/white"
android:textColorHint="@color/hint_color"
android:textCursorDrawable="@null"
android:textSize="18sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/imageView2" />
<EditText
android:id="@+id/testEmailText"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginStart="50dp"
android:layout_marginTop="10dp"
android:layout_marginEnd="50dp"
android:background="@drawable/rounded_background"
android:gravity="center_vertical"
android:hint="Email"
android:paddingStart="10dp"
android:text=""
android:textColor="@color/white"
android:textColorHint="@color/hint_color"
android:textCursorDrawable="@null"
android:textSize="18sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/imageView2" />
<EditText
android:id="@+id/testFullNameText"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginStart="50dp"
android:layout_marginTop="10dp"
android:layout_marginEnd="50dp"
android:background="@drawable/rounded_background"
android:gravity="center_vertical"
android:hint="Full Name"
android:paddingStart="10dp"
android:text=""
android:textColor="@color/white"
android:textColorHint="@color/hint_color"
android:textCursorDrawable="@null"
android:textSize="18sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/imageView2" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="50dp"
android:layout_marginStart="50dp"
android:layout_marginEnd="50dp"
android:text="Sign Up"
android:background="@drawable/rounded_button"
/>
</LinearLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/logoLayout1"
android:id="@+id/footerLayout"
android:layout_alignParentBottom="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_alignParentBottom="true">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="false"
android:text="Welcome to ....."
android:textSize="15sp" />
</LinearLayout>
</RelativeLayout>
</RelativeLayout>
这是我的AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.myapplication">
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".testLayout"
android:windowSoftInputMode="adjustResize">
</activity>
<activity android:name=".registerActivity" />
<activity android:name=".loginActivity" />
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar"
android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<meta-data
android:name="preloaded_fonts"
android:resource="@array/preloaded_fonts" />
</application>
</manifest>
adjustResize也可以与constraintLayout一起使用!
谢谢。
答案 0 :(得分:0)
尝试此操作将调整屏幕大小
将android:fitsSystemWindows =“ true”添加到scrollview
<ScrollView 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_width="match_parent"
android:fillViewport="true"
android:layout_height="match_parent"
android:background="#000000"
android:fitsSystemWindows="true"
tools:context=".testLayout">
并在RelativeLayout中添加android:layout_gravity =“ center”
<RelativeLayout
android:id="@+id/mainLayout"
android:layout_width="match_parent"
android:layout_gravity="center"
android:layout_height="wrap_content">