我的布局檔案的結構: Coordinator layout - NestedScrollView - Coordinator Layout - 我希望能夠滾動的物件
我的帶有 TextInputEditText 的 TextInputLayout 位于螢屏底部,填充時會超出螢屏范圍。當我折疊鍵盤時,它仍然無法滾動。
注意:我不想將 maxLines 設定為 Edittext 并使其本身可滾動。我希望它與其他元素一起滾動。
但是,例如,如果我將 TextView 放在螢屏底部并且它不適合,則該頁面是可滾動的。有任何想法嗎?
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fillViewport="true"
>
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<!--other items i want to scroll-->
<com.google.android.material.textfield.TextInputLayout
android:id="@ id/descriptionLayout"
android:layout_width="348dp"
android:layout_height="200dp"
android:layout_gravity="center_horizontal"
android:layout_marginTop="545dp"
android:ems="16"
android:fontFamily="@font/montserrat"
android:hint="Add image description (optional)"
android:inputType="textMultiLine|textAutoCorrect"
app:counterEnabled="true"
app:counterMaxLength="256"
app:boxBackgroundColor="@color/white"
app:srcCompat="@drawable/ic_round_cloud_upload_24"
android:textColor="#68B2A0"
android:textColorHint="#68B2A0"
app:hintTextColor="#68B2A0"
app:layout_anchor="@id/titleLayout"
app:boxStrokeErrorColor="#F75010"
app:boxStrokeColor="#68B2A0"
app:boxStrokeWidth="2dp"
app:errorIconTint="@color/error"
app:errorTextColor="@color/error"
app:layout_anchorGravity="center|bottom"
app:counterOverflowTextColor="@color/error"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
app:counterTextColor="@color/main_green"
>
<com.google.android.material.textfield.TextInputEditText
android:id="@ id/descriptionTxt"
android:ems="16"
android:textSize="18sp"
android:textColor="#68B2A0"
android:fontFamily="@font/montserrat"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:maxLines="7"
/>
</com.google.android.material.textfield.TextInputLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
</androidx.core.widget.NestedScrollView>
<!--bottom app bar-->
</androidx.coordinatorlayout.widget.CoordinatorLayout>
uj5u.com熱心網友回復:
這是因為你硬設定android:layout_marginTop="545dp"。盡量不要那樣做。另外我認為在你的情況下使用 cotaint 布局更好。只需將<androidx.coordinatorlayout.widget.CoordinatorLayout>嵌套滾動視圖內部更改為<androidx.constraintlayout.widget.ConstraintLayout>并添加此屬性:
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent
如果您需要在 fullscteen 中顯示嵌套視圖,只需更改android:layout_height="wrap_content"為android:layout_height="match_parent"
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/391815.html
標籤:安卓 安卓布局 android-xml android-textinputlayout android-nestedscrollview
