当键盘被拉起时,我一直试图让ConstraintLayout
向上滚动。理想情况下,我希望它能够将其余元素向上推,这样您就可以看到整个多行EditText
,同时使其余的布局可滚动。此布局位于Fragment
的场景中,因此我不确定这是否会阻止此工作。
这是我的XML:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:verticalScrollbarPosition="right"
android:fillViewport="true"
android:scrollbars="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">
<android.support.constraint.ConstraintLayout
android:id="@+id/constraintLayoutEditReadings"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<!-- Creates margins for the sides -->
<android.support.constraint.Guideline
android:id="@+id/guideLeftMargin"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintGuide_percent="0.05" />
<android.support.constraint.Guideline
android:id="@+id/guideRightMargin"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintGuide_percent="0.95" />
<android.support.constraint.Guideline
android:id="@+id/guideTopMargin"
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintGuide_percent="0.0" />
<android.support.constraint.Guideline
android:id="@+id/guideBottomMargin"
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintGuide_percent="0.95" />
<!-- Guideline for the EditTexts -->
<android.support.constraint.Guideline
android:id="@+id/guideEditStart"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_percent="0.33"/>
<android.support.constraint.Guideline
android:id="@+id/guideEditEnd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_percent="0.90"/>
<android.support.constraint.Guideline
android:id="@+id/guideEditReadingTop"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.47"/>
<android.support.constraint.Guideline
android:id="@+id/guideEditReadingBottom"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.85"/>
<!-- textviews -->
<TextView
android:id="@+id/lblTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/readingTitle"
android:textSize="25sp"
app:layout_constraintTop_toBottomOf="@id/guideTopMargin"
app:layout_constraintLeft_toRightOf="@id/guideLeftMargin"
android:layout_marginTop="20dp"/>
<TextView
android:id="@+id/lblAuthor"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/readingAuthor"
android:textSize="25sp"
app:layout_constraintTop_toBottomOf="@id/lblTitle"
app:layout_constraintLeft_toRightOf="@id/guideLeftMargin"
android:layout_marginTop="50dp"/>
<TextView
android:id="@+id/lblPart"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/readingPart"
android:textSize="25sp"
app:layout_constraintTop_toBottomOf="@id/lblAuthor"
app:layout_constraintLeft_toRightOf="@id/guideLeftMargin"
android:layout_marginTop="50dp"/>
<TextView
android:id="@+id/lblText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/readingText"
android:textSize="25sp"
app:layout_constraintTop_toBottomOf="@id/lblPart"
app:layout_constraintLeft_toRightOf="@id/guideLeftMargin"
android:layout_marginTop="50dp" />
<!-- Edit Texts -->
<EditText
android:id="@+id/editTitle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:hint="@string/titleHint"
android:textAlignment="center"
app:layout_constraintLeft_toRightOf="@id/guideEditStart"
app:layout_constraintRight_toLeftOf="@id/guideEditEnd"
app:layout_constraintTop_toBottomOf="@id/guideTopMargin"
android:layout_marginTop="10dp"
/>
<EditText
android:id="@+id/editAuthor"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:hint="@string/authorHint"
app:layout_constraintLeft_toRightOf="@id/guideEditStart"
app:layout_constraintRight_toLeftOf="@id/guideEditEnd"
app:layout_constraintTop_toBottomOf="@id/editTitle"
android:layout_marginTop="40dp"
android:textAlignment="center"
/>
<EditText
android:id="@+id/editPart"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:hint="@string/partHint"
android:textAlignment="center"
app:layout_constraintLeft_toRightOf="@id/guideEditStart"
app:layout_constraintRight_toLeftOf="@id/guideEditEnd"
app:layout_constraintTop_toBottomOf="@id/editAuthor"
android:layout_marginTop="35dp" />
<!-- larger EditText for the readings -->
<EditText
android:id="@+id/editReading"
android:layout_width="0dp"
android:layout_height="0dp"
android:inputType="textMultiLine"
android:lines="8"
android:gravity="start"
android:scrollbars="vertical"
android:overScrollMode="always"
android:background="@drawable/border"
app:layout_constraintTop_toBottomOf="@id/lblText"
app:layout_constraintBottom_toTopOf="@id/guideEditReadingBottom"
app:layout_constraintLeft_toRightOf="@id/guideLeftMargin"
app:layout_constraintRight_toLeftOf="@id/guideRightMargin"/>
<Button
android:id="@+id/btnSubmit"
style="@style/Widget.AppCompat.Button.Borderless"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/submitReading"
app:layout_constraintBottom_toTopOf="@id/guideBottomMargin"
app:layout_constraintLeft_toRightOf="@id/guideLeftMargin"
app:layout_constraintRight_toLeftOf="@id/guideRightMargin" />
</android.support.constraint.ConstraintLayout>
</ScrollView>
以下是布局的截图: