DividerItemDecoration没有出现在RecyclerView中 [英] DividerItemDecoration doesn't show up in RecyclerView

查看:84
本文介绍了DividerItemDecoration没有出现在RecyclerView中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现DividerItemDecoration可以与简单的一个行列表项配合使用,而对于更复杂的一项则拒绝显示.这是列表项的XML:

I found that DividerItemDecoration work fine with simple, one line list items, but with more complex one it refuses to show up. Here's the XML of list item:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    android:layout_height="wrap_content"
    android:layout_width="match_parent"
    android:layout_marginTop="5dp"
    android:layout_marginBottom="5dp"
    android:orientation="horizontal"
    xmlns:android="http://schemas.android.com/apk/res/android" >

    <ImageView
        android:layout_width="60dp"
        android:layout_height="60dp"
        android:id="@+id/imageView"
        android:transitionName="obrazek"
        android:layout_marginRight="5dp" />

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:paddingTop="5dp"
        android:paddingBottom="5dp"
        android:background="?android:attr/selectableItemBackground">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:text="Medium Text"
            android:id="@+id/nazwa"
            android:maxLines="1" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:text="Medium Text"
            android:id="@+id/odleglosc"
            android:layout_gravity="right"
            android:gravity="end"
            android:layout_below="@+id/nazwa"
            android:layout_alignParentRight="true"
            android:layout_alignParentEnd="true"
            android:clickable="false" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:text=" "
            android:id="@+id/cena"
            android:layout_below="@+id/nazwa"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true" />
        <!--
            <RatingBar
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/ratingBar"
                android:layout_below="@+id/nazwa"
                android:layout_alignParentLeft="true"
                android:layout_alignParentStart="true"
                style="@style/beerRatingBar" />
        -->

    </RelativeLayout>
</LinearLayout>

我正在为RecyclerView使用最常见的装饰器.只是不知道为什么它不想画.

I'm using most common decorator for RecyclerView. Just don't know why it don't want to draw.

recyclerView.addItemDecoration(new DividerItemDecoration(
                                getApplicationContext(), DividerItemDecoration.VERTICAL_LIST));

推荐答案

A遇到了类似的问题,但在我的情况下,它使用RelativeLayout作为我项目的根布局.将其更改为LinearLayout并起作用.

A had a similar problem but in my case it was using a RelativeLayout as the root layout of my item. Changed it to LinearLayout and it worked.

我的建议是简化项目xml,直到看到分隔符为止.

My suggestion is to simplify your item xml until you can see the divider.

这篇关于DividerItemDecoration没有出现在RecyclerView中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆