JozeRi
JozeRi

Reputation: 3429

Horizontal RecyclerView wrap_content doesn't work well on samsungs?

TL;DR - I'm using an horizontal recycler view with wrap_content width on each cell, and it's working as expected on everything except samsung devices.

my list_item.xml:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:id="@+id/scope_layout"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/bg_scope_state_normal"
        android:clickable="true"
        android:focusable="true"
        android:padding="8dp"
        android:paddingStart="16dp"
        android:paddingEnd="16dp"
        android:layout_marginStart="6dp"
        android:layout_marginEnd="6dp">

    <TextView
        android:id="@+id/scope_text"
        android:layout_centerInParent="true"
        android:background="?attr/selectableItemBackground"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="16sp"
        tools:text="2/2017"/>

</RelativeLayout>

now, this is how it looks on a samsung s3 with this code: bad behaviour

and this is how it looks if i change width of the relative layout in list_item.xml to 80dp: 80dp

now, as you can see the texts have different width and with a fixed width i am missing letters in long words, wrap_content should set the width according to the text view width, but on samsungs this doesn't work, it just stretches the layout.. am I missing something?

Upvotes: 3

Views: 158

Answers (1)

thepoosh
thepoosh

Reputation: 12587

you can remove the wrapping RelativeLayout as said by Eugen in the comment and use the recyclerview's internal system of ItemDecorator instead for drawing the nice background instead. this should fix your UI

also, you can dump the view hierarchy using the Android Monitor and see what the actual values are for the S3

Upvotes: 1

Related Questions