简体   繁体   English

在 ConstraintLayout 中的键盘输入上移动一组元素

[英]Move group of elements up on keyboard enter in ConstraintLayout

I'm currently trying to move a view previously done in LinearLayout to ConstraintLayout .我目前正在尝试将之前在LinearLayout中完成的视图移动到ConstraintLayout

The trouble I'm facing is that I need to push a view up based on the keyboard.我面临的麻烦是我需要根据键盘向上推视图。 How to create a conditional chain?如何创建条件链?

This is how I'm making the constraints:这就是我制作约束的方式:

约束

Normally I'd use window:softInputMode attribute set to adjustResize and my views work out fine.通常我会使用window:softInputMode属性设置为adjustResize并且我的视图运行良好。 Even with that, in ConstraintLayout only the button is moving up since it has a constraint with parent's bottom.即便如此,在ConstraintLayout中,只有按钮向上移动,因为它与父级底部有约束。

I tried creating a biased constraint with some margin there from the EditText to the button.我尝试创建一个从EditText到按钮的有一定边距的有偏约束。 I cannot set the bias to anything other than zero, since otherwise it would move the edit text towards the button.我不能将偏差设置为零以外的任何值,否则它会将编辑文本移向按钮。

How should I accomplish this?我应该如何做到这一点?

Try this way,试试这个方法

Add Space view between your button and your EditText like below在按钮和 EditText 之间添加 Space 视图,如下所示

<Space
        android:id="@+id/space"
        android:layout_width="0dp"
        android:layout_height="0dp"
        app:layout_constraintBottom_toTopOf="@+id/yourButtonId"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/yourEditTextId" />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM