Reputation: 148
I have a layout file which contains a RecyclerView and a FloatingActionButton. Inside of that I got multiple CardViews. The main layout file:
<?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>
The xml layout for the cardviews:
<?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:
As you can see the last checkbox is not visible because the FloatingActionButton is overlaping it. The problem is that the count of cardviews in the recyclerview isn't the same every time. The cradviews get added programmatically so I can't just set that the CheckBox of the last one should have the toStartOf -> FloatingActionButton in a xml file.
So I tried it programmatically in the adapter:
RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams)holder.cb.getLayoutParams();
params.addRule(RelativeLayout.START_OF, R.id.checkinput_btn_ready);
holder.cb.setLayoutParams(params);
This isn't working for me but I don't know what I need to do for moving the checkbox of the last cardview to the left of the FloatingActionButton.
Upvotes: 2
Views: 1591
Reputation: 1915
change your recyclerview code to this
<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"/>
this will show your last item little bit above fab icon if it doesn't try to increase the paddingbottom.
Upvotes: 4
Reputation: 587
Have you tried to get the adapter count ( then get the last item )and set margin-right in your checkbox?
Upvotes: 1