我尝试将ScrollView
替换为NestedScrollView
,并将所有视图包装在CoordinatorLayout
中,但这无济于事。
没有android:windowSoftInputMode="adjustPan"
,它可以工作,但是我不喜欢打开键盘时布局的变化;我希望键盘重叠布局,而不是挤压布局。
屏幕截图
activity_login.xml
<?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"
tools:context=".LoginActivity"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
android:paddingLeft="40dp"
android:paddingRight="40dp"
android:paddingBottom="20dp">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/ImageView_nyatrix_logo"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:contentDescription="@string/app_name"
app:layout_constraintBottom_toTopOf="@id/til_login"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/ic_logo_big" />
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/til_login"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintBottom_toTopOf="@id/til_password"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/ImageView_nyatrix_logo">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/EditText_login"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="login/phone/email" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/til_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintBottom_toTopOf="@id/til_homeServer"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/til_login">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/EditText_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="password" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/til_homeServer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintBottom_toTopOf="@id/til_identityServer"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/til_password">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/EditText_homeServer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="homeserver"
android:text="https://matrix.org"/>
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/til_identityServer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintBottom_toTopOf="@id/Button_login"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/til_homeServer">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/EditText_identityServer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="identity server"
android:text="https://vector.im" />
</com.google.android.material.textfield.TextInputLayout>
<Button
android:id="@+id/Button_login"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Login"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/til_identityServer" />
</androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView>
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="ru.sabernyan.nyatrix">
<application
android:allowBackup="true"
android:fullBackupContent="false"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme"
tools:ignore="GoogleAppIndexingWarning"
android:name="android.support.multidex.MultiDexApplication">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".LoginActivity"
android:theme="@style/AppTheme.NoActionBar"
android:windowSoftInputMode="adjustPan" />
</application>
</manifest>