我有一個布局,螢屏底部有一個EditText和Button。我希望與NestedScrollView一起RecyclerView占用 2 個元素上方的空間。但是,他們只占其中的一部分。
這是我的代碼
<?xml version="1.0" encoding="utf-8"?>
<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"
tools:context=".HomeActivity">
<androidx.core.widget.NestedScrollView
android:id="@ id/nestedScrollView"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintBottom_toTopOf="@ id/etMessage"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:context=".HomeActivity">
<androidx.recyclerview.widget.RecyclerView
android:id="@ id/rvMessages"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:nestedScrollingEnabled="true" />
</androidx.core.widget.NestedScrollView>
<EditText
android:id="@ id/etMessage"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:ems="10"
android:hint="Enter your message"
android:inputType="text"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@ id/btnSend"
app:layout_constraintStart_toStartOf="parent" />
<Button
android:id="@ id/btnSend"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Send"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@ id/etMessage" />
</androidx.constraintlayout.widget.ConstraintLayout>
uj5u.com熱心網友回復:
在 NestedScrollView 中添加這一行
android:fillViewport="true"
uj5u.com熱心網友回復:
如果 RecyclerView 中有必要數量的專案,它將具有與 NestedScrollView 相同的高度。您可以計算專案的必要高度。而且我真的不認為您的布局中需要 NestedScrollView,因為沒有它可以滾動 RecyclerView。
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/435279.html
標籤:安卓 xml 安卓布局 android-recyclerview android-nestedscrollview
