Reputation: 957
i have a constraintlayout with a recyclerview. some items of my list not appears because the recyclerview is croping. When i see the constraint bottom of recyclerview to bottom of my parent everything works fine in the bottom, but i have other problem in the top. The recycler view going to the back of my cardview, cuting some itens of top.
is that my layout:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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:background="@color/shadow"
android:orientation="vertical"
android:paddingBottom="8dp">
<android.support.v7.widget.CardView
android:id="@+id/myCardView"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
app:cardCornerRadius="4dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="@+id/txtExpenseValue"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginLeft="16dp"
android:layout_marginTop="8dp"
android:ems="10"
android:inputType="textPersonName"
android:background="@android:color/transparent"
android:hint="@string/expense_category"
android:drawableLeft="@drawable/ic_folder"
android:drawablePadding="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/btnRegister"
android:layout_width="51dp"
android:layout_height="52dp"
android:layout_marginBottom="8dp"
android:layout_marginRight="10dp"
android:layout_marginTop="8dp"
android:background="@drawable/btn_add_newdesign"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
</android.support.v7.widget.CardView>
<TextView
android:id="@+id/txtTotalPrice"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="15dp"
android:text="R$ 15.000,00"
android:textSize="24sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toBottomOf="@id/myCardView" />
<android.support.v7.widget.RecyclerView
android:id="@+id/myRecyclerView"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:background="@color/shadow"
android:padding="4dp"
android:scrollbars="vertical"
android:layout_marginBottom="4dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/txtTotalPrice" />
</android.support.constraint.ConstraintLayout>
im tried to use margin to correct, but not works.
Upvotes: 1
Views: 522
Reputation: 6316
Constrain the bottom of the RecyclerView
to the bottom of the parent and set its android:layout_height
to 0dp
to match constraints instead of match_parent
. It's not recommended to use match_parent
for Views
contained in a ConstraintLayout
as stated in the documentation:
Important: MATCH_PARENT is not recommended for widgets contained in a ConstraintLayout. Similar behavior can be defined by using MATCH_CONSTRAINT with the corresponding left/right or top/bottom constraints being set to "parent".
Upvotes: 1