gpt4 book ai didi

android - 单击 EditText 时 View 不会一直向上滚动

转载 作者:行者123 更新时间:2023-12-05 00:08:33 24 4
gpt4 key购买 nike

当我点击 3 个编辑文本中的一个时,我的键盘出现并且 View 向上滚动一点。但是我的布局应该一直向上移动。我的 xml 文件:

<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">

<ScrollView
android:id="@+id/scrollView"
android:fillViewport="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="@+id/toolbar"
app:layout_constraintVertical_bias="0.01999998">

<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="126dp">

<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="@dimen/padding_default"
android:padding="@dimen/padding_small"
android:paddingHorizontal="@dimen/padding_default"
app:layout_constraintTop_toTopOf="parent"
tools:layout_editor_absoluteX="16dp" />

<EditText
android:id="@+id/instructionsEditText"
android:layout_width="match_parent"
android:layout_height="600dp"
android:layout_margin="@dimen/padding_default"
android:gravity="top|start"
android:padding="@dimen/padding_small"
android:paddingHorizontal="@dimen/padding_default"
app:layout_constraintTop_toBottomOf="@+id/amountPersonsEditText" />

<EditText
android:id="@+id/notesEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="@dimen/padding_default"
android:padding="@dimen/padding_small"
android:paddingHorizontal="@dimen/padding_default"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="@+id/instructionsEditText"
tools:layout_editor_absoluteX="16dp" />
</androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView>

<android.widget.Button
android:id="@+id/saveInstructionsButton"
style="@style/buttonStyle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/padding_default"
android:gravity="center"
android:imeOptions="actionDone"
android:text="@string/instructions_button_text"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>

我的安卓 list :

    <activity
android:name=".ui.instructions.InstructionsActivity"
android:windowSoftInputMode="adjustResize"
android:screenOrientation="portrait" />

我也试过这个:

fun ScrollView.moveToTop() {
this.isFocusableInTouchMode = true
this.fullScroll(View.FOCUS_DOWN)
this.smoothScrollTo(0, bottom)
}

但是按钮在 ScrollView 之外,按钮底部应该在键盘顶部。

开始:

enter image description here

实际:

enter image description here

预期:

enter image description here

最佳答案

在 ScrollView 中添加以下代码:

    android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toTopOf="@+id/saveInstructionsButton"

底部按钮中的代码:

    app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"

示例代码:

<androidx.constraintlayout.widget.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">

<ScrollView
android:id="@+id/scrollView"
android:fillViewport="true"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toTopOf="@+id/saveInstructionsButton">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">

<EditText
android:id="@+id/amountPersonsEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="@dimen/padding_default"
android:padding="@dimen/padding_small"
android:paddingHorizontal="@dimen/padding_default"
app:layout_constraintTop_toTopOf="parent"
tools:layout_editor_absoluteX="16dp"
android:focusableInTouchMode="true" />

<EditText
android:id="@+id/instructionsEditText"
android:layout_width="match_parent"
android:layout_height="600dp"
android:layout_margin="@dimen/padding_default"
android:gravity="top|start"
android:padding="@dimen/padding_small"
android:paddingHorizontal="@dimen/padding_default"
android:focusableInTouchMode="true"
app:layout_constraintTop_toBottomOf="@+id/amountPersonsEditText" />

<EditText
android:id="@+id/notesEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="@dimen/padding_default"
android:padding="@dimen/padding_small"
android:paddingHorizontal="@dimen/padding_default"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="@+id/instructionsEditText"
tools:layout_editor_absoluteX="16dp"
android:focusableInTouchMode="true"/>
</androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView>
<android.widget.Button
android:id="@+id/saveInstructionsButton"
style="@style/buttonStyle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:gravity="center"
android:imeOptions="actionDone"
android:text="@string/instructions_button_text"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"/>
</androidx.constraintlayout.widget.ConstraintLayout>

list 文件代码:

<activity
android:name=".ui.instructions.InstructionsActivity"
android:windowSoftInputMode="adjustResize"
android:screenOrientation="portrait" />

以上代码的输出是:

enter image description here

关于android - 单击 EditText 时 View 不会一直向上滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69043158/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com