CardView not shown in RecyclerView

前端 未结 3 526
面向向阳花
面向向阳花 2021-01-25 14:18

I have a problem which is driving me nuts. Basically it is a simple RecyclerView which displays a cardview. There are a lot of posts out there already, which I checked. I have a

3条回答
  •  面向向阳花
    2021-01-25 15:12

    Your code is fine, The problem is with layout file: document_item.xml:

        
    
            mistake
                android:layout_height="wrap_content"
                android:layout_weight="0.25" />
    
            mistake
                android:gravity="center_horizontal"
                android:orientation="vertical"
                ...
    

    The second LinearLayout gets its height from parent (first LinearLayout), and the first one gets its height from its only child: ImageView (so without no drawable set, the second layout's height will be zero! ), if you set a drawable for ImageView (in onBindViewHolder method or in layout xml file) it probably crops some of TextView items, Also when you set android:layout_width to "wrap_content", actually you're ignoring layout_weight.

    So edit layout file like this:

              ...
              
    
            

提交回复
热议问题