【发布时间】:2018-09-02 09:44:56
【问题描述】:
我在CardView 中有一个RecyclerView,但我有一个问题,我在RecyclerView 的底部有2 个按钮,所以我把它们放在RelativeLayout 的末尾并给它们parent_bottom 真的所以我可以使它们可见,但这会使CardView 具有全屏,无论RecyclerView 是否有项目。
XML 代码:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="12dp"
app:cardElevation="8dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/white"
android:padding="8dp">
<TextView
android:id="@+id/activeInspections"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text=" Your active inspections"
android:textSize="18sp" />
<android.support.v7.widget.RecyclerView
android:id="@+id/rvActiveInspections"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@id/btnClear"
android:layout_below="@+id/activeInspections"
android:layout_marginTop="8dp" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_alignParentBottom="true"
android:layout_marginTop="8dp"
android:id="@+id/btnClear"
android:background="?selectableItemBackground"
android:text="CLear" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginBottom="8dp"
android:layout_marginTop="8dp"
android:id="@+id/btnContinue"
android:layout_alignParentBottom="true"
android:background="?selectableItemBackground"
android:text="Continue"
android:textColor="@color/blue_normal" />
</RelativeLayout>
</android.support.v7.widget.CardView>
当我尝试另一件事时,下面的代码使它们低于RecyclerView,因此它固定以防万一,另一种情况如图所示(底部的按钮未显示)
那么如何解决这个问题?
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="12dp"
app:cardElevation="8dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/white"
android:padding="8dp">
<TextView
android:id="@+id/activeInspections"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text=" Your active inspections"
android:textSize="18sp" />
<android.support.v7.widget.RecyclerView
android:id="@+id/rvActiveInspections"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/activeInspections"
android:layout_marginTop="8dp" />
<Button
android:id="@+id/btnClear"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/rvActiveInspections"
android:layout_marginBottom="8dp"
android:layout_marginTop="8dp"
android:background="?selectableItemBackground"
android:text="CLear" />
<Button
android:id="@+id/btnContinue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="@+id/rvActiveInspections"
android:layout_marginBottom="8dp"
android:layout_marginTop="8dp"
android:background="?selectableItemBackground"
android:text="Continue"
android:textColor="@color/blue_normal" />
</RelativeLayout>
</android.support.v7.widget.CardView>
目标是这个,当项目扩展时,它只适合屏幕并且不会超出它
【问题讨论】:
标签: android android-recyclerview android-cardview