[英]how to I set the height to fit the whole screen?
我有以下活動
<TextView
android:id="@+id/textView"
android:layout_width="130dp"
android:layout_height="43dp"
android:layout_marginStart="20dp"
android:layout_marginTop="24dp"
android:fontFamily="@font/lato"
android:text="Home"
android:textColor="#000000"
android:textSize="30sp"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/featured_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:layout_marginLeft="20dp"
android:layout_marginTop="20dp"
android:fontFamily="@font/cerapro"
android:textColor="#000000"
android:textStyle="bold"
app:layout_constraintStart_toStartOf="@+id/textView"
app:layout_constraintTop_toBottomOf="@+id/textView"
tools:layout_editor_absoluteX="20dp" />
<ImageView
android:id="@+id/featured_image"
android:layout_width="match_parent"
android:layout_height="167dp"
android:layout_marginTop="20dp"
android:scaleType="fitXY"
app:layout_constraintStart_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/featured_title"
tools:srcCompat="@tools:sample/avatars[0]" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="248dp"
android:layout_marginTop="32dp"
app:layout_constraintTop_toBottomOf="@+id/featured_image"
/>
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/navigation"
android:layout_width="match_parent"
android:layout_height="80dp"
android:layout_marginStart="0dp"
android:layout_marginEnd="0dp"
android:background="?android:attr/windowBackground"
app:layout_constraintTop_toBottomOf="@+id/recyclerView"
app:menu="@menu/navigation" />
在繪制導航視圖后,如何設置 recycleView 高度以使其適合屏幕的其余部分?
另外如何確保底部導航視圖始終位於底部?
據我所知,最好的解決方案是將height = 0用於回收者視圖。 做:
1- 確保底部導航始終位於底部:
app:layout_constraintBottom_toBottomOf="parent"
2- 為確保您的 recycleView 填充屏幕的剩余部分,請使用:
android:layout_height="0dp"
app:layout_constraintTop_toBottomOf="@+id/featured_image"
app:layout_constraintBottom_toTopOf="@+id/navigation"
總結一下你的代碼應該是這樣的:
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginTop="32dp"
app:layout_constraintTop_toBottomOf="@+id/featured_image"
app:layout_constraintBottom_toTopOf="@+id/navigation" />
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/navigation"
android:layout_width="match_parent"
android:layout_height="80dp"
android:layout_marginStart="0dp"
android:layout_marginEnd="0dp"
android:background="?android:attr/windowBackground"
app:layout_constraintBottom_toBottomOf="parent"
app:menu="@menu/navigation" />
如果您使用具有vertical
方向的LinearLayout
,則將所有其他視圖的高度設置為wrap_content
並在要填充屏幕的視圖上使用layout_height="0dp"
layout_weight="1"
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.