水平的RecyclerView在三星手机上wrap_content不太好用?

3

TL;DR - 我正在使用一个水平的可回收视图,每个单元格宽度为wrap_content,在除三星设备外的所有设备上都能正常工作。

我的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>

现在,这是在三星S3上使用此代码的效果: bad behaviour 如果我将list_item.xml中相对布局的宽度更改为80dp,则效果如下: 80dp 现在,您可以看到文本具有不同的宽度,并且使用固定宽度时,长单词中缺少字母,wrap_content应根据文本视图宽度设置宽度,但在三星手机上,这并不起作用,它只会拉伸布局... 我是否遗漏了什么?

1
小小的不相关评论。为什么需要相对布局?如果你只是使用TextView,那么你为什么需要它呢? - Eugen Martynov
给那个人一个拥抱,我认为这会解决你的问题。 - thepoosh
1个回答

1
你可以按照Eugen在评论中提到的方法,删除包装RelativeLayout,并使用recyclerview的内部系统ItemDecorator来绘制漂亮的背景,这样应该可以解决你的UI问题。
另外,你可以使用Android Monitor来转储视图层次结构,并查看S3的实际值。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接