RecyclerView item ConstraintLayout messing up while using GridLayoutManager
up vote
2
down vote
favorite
I'm using GridLayoutManager
in my RecyclerView
with a spanCount
of 2.
Following is the layout of RecyclerView
item. It is a ConstraintLayout
which is wrapped up in a CardView
:
<android.support.v7.widget.CardView
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="wrap_content"
android:layout_margin="@dimen/cardview_margin"
android:foreground="?android:attr/selectableItemBackground"
app:cardBackgroundColor="@android:color/white"
app:cardCornerRadius="4dp">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/tv_title"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:text="Title"
android:textAllCaps="true"
android:textColor="@color/colorPrimary"
android:textSize="16sp"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/tv_sub_title"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="Subtitle"
android:textAllCaps="false"
android:textSize="14sp"
app:layout_constraintEnd_toEndOf="@+id/tv_title"
app:layout_constraintStart_toStartOf="@+id/tv_title"
app:layout_constraintTop_toBottomOf="@+id/tv_title" />
<ImageView
android:id="@+id/iv_favorite"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:scaleX="1.07"
android:scaleY="1.07"
android:src="@drawable/ic_star_blank_grey"
app:layout_constraintBottom_toBottomOf="@+id/iv_locked"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="@+id/iv_locked"/>
<ImageView
android:id="@+id/iv_locked"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
android:scaleX="1.0"
android:scaleY="1.0"
android:src="@drawable/ic_lock_open_grey"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/iv_favorite"
app:layout_constraintTop_toBottomOf="@+id/tv_sub_title" />
</android.support.constraint.ConstraintLayout>
</android.support.v7.widget.CardView>
The problem arises when GridLayoutManager
tends to increase the height of a RecyclerView
item according to the height of the item in second column. Both the ImageView
icons leave the parent bottom and tend to stick to the TextView
tv_sub_title
as in the screenshot below:
Kindly let me know how to fix this such that both the icons stay at the bottom when the height of the item layout is increased by the GridLayoutManager
.
Thanks
android android-recyclerview android-constraintlayout gridlayoutmanager
add a comment |
up vote
2
down vote
favorite
I'm using GridLayoutManager
in my RecyclerView
with a spanCount
of 2.
Following is the layout of RecyclerView
item. It is a ConstraintLayout
which is wrapped up in a CardView
:
<android.support.v7.widget.CardView
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="wrap_content"
android:layout_margin="@dimen/cardview_margin"
android:foreground="?android:attr/selectableItemBackground"
app:cardBackgroundColor="@android:color/white"
app:cardCornerRadius="4dp">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/tv_title"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:text="Title"
android:textAllCaps="true"
android:textColor="@color/colorPrimary"
android:textSize="16sp"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/tv_sub_title"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="Subtitle"
android:textAllCaps="false"
android:textSize="14sp"
app:layout_constraintEnd_toEndOf="@+id/tv_title"
app:layout_constraintStart_toStartOf="@+id/tv_title"
app:layout_constraintTop_toBottomOf="@+id/tv_title" />
<ImageView
android:id="@+id/iv_favorite"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:scaleX="1.07"
android:scaleY="1.07"
android:src="@drawable/ic_star_blank_grey"
app:layout_constraintBottom_toBottomOf="@+id/iv_locked"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="@+id/iv_locked"/>
<ImageView
android:id="@+id/iv_locked"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
android:scaleX="1.0"
android:scaleY="1.0"
android:src="@drawable/ic_lock_open_grey"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/iv_favorite"
app:layout_constraintTop_toBottomOf="@+id/tv_sub_title" />
</android.support.constraint.ConstraintLayout>
</android.support.v7.widget.CardView>
The problem arises when GridLayoutManager
tends to increase the height of a RecyclerView
item according to the height of the item in second column. Both the ImageView
icons leave the parent bottom and tend to stick to the TextView
tv_sub_title
as in the screenshot below:
Kindly let me know how to fix this such that both the icons stay at the bottom when the height of the item layout is increased by the GridLayoutManager
.
Thanks
android android-recyclerview android-constraintlayout gridlayoutmanager
add a comment |
up vote
2
down vote
favorite
up vote
2
down vote
favorite
I'm using GridLayoutManager
in my RecyclerView
with a spanCount
of 2.
Following is the layout of RecyclerView
item. It is a ConstraintLayout
which is wrapped up in a CardView
:
<android.support.v7.widget.CardView
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="wrap_content"
android:layout_margin="@dimen/cardview_margin"
android:foreground="?android:attr/selectableItemBackground"
app:cardBackgroundColor="@android:color/white"
app:cardCornerRadius="4dp">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/tv_title"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:text="Title"
android:textAllCaps="true"
android:textColor="@color/colorPrimary"
android:textSize="16sp"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/tv_sub_title"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="Subtitle"
android:textAllCaps="false"
android:textSize="14sp"
app:layout_constraintEnd_toEndOf="@+id/tv_title"
app:layout_constraintStart_toStartOf="@+id/tv_title"
app:layout_constraintTop_toBottomOf="@+id/tv_title" />
<ImageView
android:id="@+id/iv_favorite"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:scaleX="1.07"
android:scaleY="1.07"
android:src="@drawable/ic_star_blank_grey"
app:layout_constraintBottom_toBottomOf="@+id/iv_locked"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="@+id/iv_locked"/>
<ImageView
android:id="@+id/iv_locked"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
android:scaleX="1.0"
android:scaleY="1.0"
android:src="@drawable/ic_lock_open_grey"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/iv_favorite"
app:layout_constraintTop_toBottomOf="@+id/tv_sub_title" />
</android.support.constraint.ConstraintLayout>
</android.support.v7.widget.CardView>
The problem arises when GridLayoutManager
tends to increase the height of a RecyclerView
item according to the height of the item in second column. Both the ImageView
icons leave the parent bottom and tend to stick to the TextView
tv_sub_title
as in the screenshot below:
Kindly let me know how to fix this such that both the icons stay at the bottom when the height of the item layout is increased by the GridLayoutManager
.
Thanks
android android-recyclerview android-constraintlayout gridlayoutmanager
I'm using GridLayoutManager
in my RecyclerView
with a spanCount
of 2.
Following is the layout of RecyclerView
item. It is a ConstraintLayout
which is wrapped up in a CardView
:
<android.support.v7.widget.CardView
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="wrap_content"
android:layout_margin="@dimen/cardview_margin"
android:foreground="?android:attr/selectableItemBackground"
app:cardBackgroundColor="@android:color/white"
app:cardCornerRadius="4dp">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/tv_title"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:text="Title"
android:textAllCaps="true"
android:textColor="@color/colorPrimary"
android:textSize="16sp"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/tv_sub_title"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="Subtitle"
android:textAllCaps="false"
android:textSize="14sp"
app:layout_constraintEnd_toEndOf="@+id/tv_title"
app:layout_constraintStart_toStartOf="@+id/tv_title"
app:layout_constraintTop_toBottomOf="@+id/tv_title" />
<ImageView
android:id="@+id/iv_favorite"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:scaleX="1.07"
android:scaleY="1.07"
android:src="@drawable/ic_star_blank_grey"
app:layout_constraintBottom_toBottomOf="@+id/iv_locked"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="@+id/iv_locked"/>
<ImageView
android:id="@+id/iv_locked"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
android:scaleX="1.0"
android:scaleY="1.0"
android:src="@drawable/ic_lock_open_grey"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/iv_favorite"
app:layout_constraintTop_toBottomOf="@+id/tv_sub_title" />
</android.support.constraint.ConstraintLayout>
</android.support.v7.widget.CardView>
The problem arises when GridLayoutManager
tends to increase the height of a RecyclerView
item according to the height of the item in second column. Both the ImageView
icons leave the parent bottom and tend to stick to the TextView
tv_sub_title
as in the screenshot below:
Kindly let me know how to fix this such that both the icons stay at the bottom when the height of the item layout is increased by the GridLayoutManager
.
Thanks
android android-recyclerview android-constraintlayout gridlayoutmanager
android android-recyclerview android-constraintlayout gridlayoutmanager
edited Nov 10 at 19:19
asked Nov 10 at 7:11
Shahood ul Hassan
409
409
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
up vote
1
down vote
To keep the iv_locked
aligned to the bottom between its vertical constraints you need to set the maximum vertical bias by adding the app:layout_constraintVertical_bias="1"
attribute
to it. Since the iv_favorite
is vertically constrained to the iv_locked
, it will automatically be in the appropriate position.
I have already tried using vertical bias but somehow it doesn't work either.
– Shahood ul Hassan
Nov 10 at 10:29
add a comment |
up vote
1
down vote
Ok, with some hit & trial and taking @Pawel Laskowski answer a bit further, here is what solved the issue:
- Add
app:layout_constraintVertical_bias="1"
attribute toiv_locked
- Change
android:layout_height
of theConstraintLayout
fromwrap_content
tomatch_parent
.
ConstraintLayout
is pretty easy to get started with but quite hard to master. Thanks for the help @Pawel Laskowski.
1
That's correct, good find.match_parent
for height is needed for theConstraintLayout
to fill the height of theCardView
. Otherwise there will not be any difference. It's easy to miss.
– Pawel Laskowski
Nov 10 at 10:56
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
To keep the iv_locked
aligned to the bottom between its vertical constraints you need to set the maximum vertical bias by adding the app:layout_constraintVertical_bias="1"
attribute
to it. Since the iv_favorite
is vertically constrained to the iv_locked
, it will automatically be in the appropriate position.
I have already tried using vertical bias but somehow it doesn't work either.
– Shahood ul Hassan
Nov 10 at 10:29
add a comment |
up vote
1
down vote
To keep the iv_locked
aligned to the bottom between its vertical constraints you need to set the maximum vertical bias by adding the app:layout_constraintVertical_bias="1"
attribute
to it. Since the iv_favorite
is vertically constrained to the iv_locked
, it will automatically be in the appropriate position.
I have already tried using vertical bias but somehow it doesn't work either.
– Shahood ul Hassan
Nov 10 at 10:29
add a comment |
up vote
1
down vote
up vote
1
down vote
To keep the iv_locked
aligned to the bottom between its vertical constraints you need to set the maximum vertical bias by adding the app:layout_constraintVertical_bias="1"
attribute
to it. Since the iv_favorite
is vertically constrained to the iv_locked
, it will automatically be in the appropriate position.
To keep the iv_locked
aligned to the bottom between its vertical constraints you need to set the maximum vertical bias by adding the app:layout_constraintVertical_bias="1"
attribute
to it. Since the iv_favorite
is vertically constrained to the iv_locked
, it will automatically be in the appropriate position.
answered Nov 10 at 9:31
Pawel Laskowski
1,4801512
1,4801512
I have already tried using vertical bias but somehow it doesn't work either.
– Shahood ul Hassan
Nov 10 at 10:29
add a comment |
I have already tried using vertical bias but somehow it doesn't work either.
– Shahood ul Hassan
Nov 10 at 10:29
I have already tried using vertical bias but somehow it doesn't work either.
– Shahood ul Hassan
Nov 10 at 10:29
I have already tried using vertical bias but somehow it doesn't work either.
– Shahood ul Hassan
Nov 10 at 10:29
add a comment |
up vote
1
down vote
Ok, with some hit & trial and taking @Pawel Laskowski answer a bit further, here is what solved the issue:
- Add
app:layout_constraintVertical_bias="1"
attribute toiv_locked
- Change
android:layout_height
of theConstraintLayout
fromwrap_content
tomatch_parent
.
ConstraintLayout
is pretty easy to get started with but quite hard to master. Thanks for the help @Pawel Laskowski.
1
That's correct, good find.match_parent
for height is needed for theConstraintLayout
to fill the height of theCardView
. Otherwise there will not be any difference. It's easy to miss.
– Pawel Laskowski
Nov 10 at 10:56
add a comment |
up vote
1
down vote
Ok, with some hit & trial and taking @Pawel Laskowski answer a bit further, here is what solved the issue:
- Add
app:layout_constraintVertical_bias="1"
attribute toiv_locked
- Change
android:layout_height
of theConstraintLayout
fromwrap_content
tomatch_parent
.
ConstraintLayout
is pretty easy to get started with but quite hard to master. Thanks for the help @Pawel Laskowski.
1
That's correct, good find.match_parent
for height is needed for theConstraintLayout
to fill the height of theCardView
. Otherwise there will not be any difference. It's easy to miss.
– Pawel Laskowski
Nov 10 at 10:56
add a comment |
up vote
1
down vote
up vote
1
down vote
Ok, with some hit & trial and taking @Pawel Laskowski answer a bit further, here is what solved the issue:
- Add
app:layout_constraintVertical_bias="1"
attribute toiv_locked
- Change
android:layout_height
of theConstraintLayout
fromwrap_content
tomatch_parent
.
ConstraintLayout
is pretty easy to get started with but quite hard to master. Thanks for the help @Pawel Laskowski.
Ok, with some hit & trial and taking @Pawel Laskowski answer a bit further, here is what solved the issue:
- Add
app:layout_constraintVertical_bias="1"
attribute toiv_locked
- Change
android:layout_height
of theConstraintLayout
fromwrap_content
tomatch_parent
.
ConstraintLayout
is pretty easy to get started with but quite hard to master. Thanks for the help @Pawel Laskowski.
answered Nov 10 at 10:42
Shahood ul Hassan
409
409
1
That's correct, good find.match_parent
for height is needed for theConstraintLayout
to fill the height of theCardView
. Otherwise there will not be any difference. It's easy to miss.
– Pawel Laskowski
Nov 10 at 10:56
add a comment |
1
That's correct, good find.match_parent
for height is needed for theConstraintLayout
to fill the height of theCardView
. Otherwise there will not be any difference. It's easy to miss.
– Pawel Laskowski
Nov 10 at 10:56
1
1
That's correct, good find.
match_parent
for height is needed for the ConstraintLayout
to fill the height of the CardView
. Otherwise there will not be any difference. It's easy to miss.– Pawel Laskowski
Nov 10 at 10:56
That's correct, good find.
match_parent
for height is needed for the ConstraintLayout
to fill the height of the CardView
. Otherwise there will not be any difference. It's easy to miss.– Pawel Laskowski
Nov 10 at 10:56
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53236799%2frecyclerview-item-constraintlayout-messing-up-while-using-gridlayoutmanager%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown