我有一个布局文件,其中包含 RecyclerView 和 FloatingActionButton。在里面我有多个 CardView。
主要布局文件:
<?xml version="1.0" encoding="utf-8"?>
<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">
<include layout="@layout/toolbar"/>
<android.support.v7.widget.RecyclerView
android:id="@+id/checkinput_rv"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/checkinput_cv_top"
android:layout_marginTop="8dp"/>
<android.support.design.widget.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="16dp"
android:layout_marginBottom="16dp"
android:clickable="true"
app:fabSize="normal"
app:srcCompat="@drawable/ic_arrow_forward_white_24dp"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:id="@+id/checkinput_btn_ready" />
</RelativeLayout>
卡片视图的 xml 布局:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/cardview_checkinput_tv_category"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="16dp"
android:layout_marginTop="16dp"
android:layout_marginRight="8dp"
android:text="Stadt:"
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
android:layout_toStartOf="@+id/cardview_checkinput_cb" />
<TextView
android:id="@+id/cardview_checkinput_tv_input"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/cardview_checkinput_tv_category"
android:layout_alignStart="@+id/cardview_checkinput_tv_category"
android:layout_marginBottom="16dp"
android:layout_marginTop="8dp"
android:layout_marginRight="8dp"
android:text="TextView"
android:layout_toStartOf="@+id/cardview_checkinput_cb" />
<CheckBox
android:id="@+id/cardview_checkinput_cb"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true" />
</RelativeLayout>
</android.support.v7.widget.CardView>
</RelativeLayout>
The problem is that the checkboxes of the cardviews are on the right side of the cardviews.
It looks like this:
正如您所看到的,最后一个复选框不可见,因为 FloatingActionButton 与它重叠。问题是回收视图中的卡片视图计数每次都不相同。 cradviews 是以编程方式添加的,所以我不能只设置最后一个复选框应该在 xml 文件中具有 toStartOf -> FloatingActionButton 。
所以我在适配器中以编程方式尝试了它:
RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams)holder.cb.getLayoutParams();
params.addRule(RelativeLayout.START_OF, R.id.checkinput_btn_ready);
holder.cb.setLayoutParams(params);
这对我不起作用,但我不知道需要做什么才能将最后一个卡片视图的复选框移动到 FloatingActionButton 的左侧。
将您的 recyclerview 代码更改为此
<android.support.v7.widget.RecyclerView
android:id="@+id/checkinput_rv"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="100dp"
android:clipToPadding="false"
android:layout_below="@+id/checkinput_cv_top"
android:layout_marginTop="8dp"/>
如果它不尝试增加 paddingbottom,这将在 fab 图标上方显示您的最后一个项目。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)