Android 根据键盘高度使用偏移移动视图[约束布局]

Android 根据键盘高度使用偏移移动视图[约束布局],android,android-constraintlayout,Android,Android Constraintlayout,我正在制作一个应用程序,其中我决定使用约束布局。在建议的设计中,右下角有一个按钮,当它出现时,需要随着键盘向上移动,如图所示: 我可以通过编程设置按钮的垂直偏差来向上移动按钮: ConstraintSet constraintSet = new ConstraintSet(); constraintSet.clone(constraintLayout); constraintSet.setVerticalBias(buttonNext.getId(), (float) 0); constrai

我正在制作一个应用程序,其中我决定使用约束布局。在建议的设计中,右下角有一个按钮,当它出现时,需要随着键盘向上移动,如图所示:

我可以通过编程设置按钮的垂直偏差来向上移动按钮:

ConstraintSet constraintSet = new ConstraintSet();
constraintSet.clone(constraintLayout);
constraintSet.setVerticalBias(buttonNext.getId(), (float) 0);
constraintSet.applyTo(constraintLayout);
但我想将按钮移动到键盘正上方,如上图所示。通过搜索,我找到了一些解决方案,可以找到键盘的高度。但我不知道我应该怎么计算偏差和键盘高度。我不确定用于偏差的单位(可能是百分比?因为在编辑器中它的值是1-100),键盘高度将以dps为单位

如果有人能帮助我的逻辑或提出一些其他解决方案,以创建上述布局,将不胜感激

android:windowSoftInputMode="adjustResize"

将此添加到活动标记中

我通过在
AndroidManifest.xml
文件中为
活动
标记设置
android:windowSoftInputMode=“adjustResize”
属性来实现该行为,如下所示:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.myapplication">

    <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=".MainActivity"
            android:windowSoftInputMode="adjustResize">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>
结果是:


感谢您的详细回答。我已经尝试过这个方法,但如果我隐藏通知栏(通过主题或编程)它就不起作用了。您能进一步建议一些方法来解决这个问题吗?因为根据我提供的UI设计,应该没有通知和标题栏。
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
    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:layout_height="match_parent"
    tools:context=".MainActivity">

    <EditText
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <ImageView
        android:src="@android:drawable/btn_star"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent" />

</android.support.constraint.ConstraintLayout>