Reputation: 4415
When using a recycler view with LinearLayoutManager.HORIZONTAL and height as wrap_content
is it trying to keep the list items having the same height?
It seems it does and some text is cut off. How can I solve this?
This is the layout for the item
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:background="@drawable/boundaries"
android:paddingTop="16dp"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:layout_marginEnd="16dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="16dp"
android:layout_height="16dp"
android:orientation="vertical"
android:gravity="center"
>
<ImageView
android:layout_width="16dp"
android:layout_height="16dp"
android:layout_gravity="center"
android:scaleType="fitCenter"
android:gravity="center"
android:src="@drawable/my_icon”
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:layout_marginStart="12dp"
android:layout_marginEnd="16dp"
android:layout_marginBottom="16dp"
android:maxWidth="200sp"
android:text="Some text of various length"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
android:includeFontPadding="false"
android:layout_marginStart="12dp"
android:layout_marginBottom="16dp"
android:gravity="bottom"
android:text="Some text that is not more than a line"
/>
</LinearLayout>
</LinearLayout>
Upvotes: 5
Views: 3831
Reputation: 2508
RecyclerView
keeps same height by default. It uses max height from visible item view layouts as its height at rendering time. So this causes a problem of text cut-off as there might be an item which has large content than visible items.
In my opinion, it's not much needed to create a custom layout manager like this guy did. For performance and usability, I think it's just better to guess the max height of your item view and set it to RecyclerView height as a constant like in dp size.
If you really want to set the correct height, you need to write some java code to estimate actual height of item views. RecyclerView should have its own height and this is determined at rendering time. And contents are dynamic. Therefore you need to write some code to estimate all of your item views and find the max height to set as RecyclerView's height in java code.
Upvotes: 2