0

I have a ListView and inside it I want horizontal RecyclerView with custom items. Problem is that somehow TextView under each image isn't displayed.

enter image description here

Main ListView item with RecyclerView

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <TextView android:id="@+id/category_title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="start"
        android:textSize="20sp"
        android:layout_marginRight="10dp"/>

    <android.support.v7.widget.RecyclerView
        android:id="@+id/horizontal_recycler_view"
        android:scrollbars="vertical"
        android:layout_width="match_parent"
        android:layout_height="110dp" />
</LinearLayout>

Single item of RecyclerView

<LinearLayout
    android:layout_width="100dp"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    xmlns:android="http://schemas.android.com/apk/res/android" >

    <ImageView android:id="@+id/horizontal_list_image"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal" />

    <TextView android:id="@+id/horizontal_list_text"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:text="FFFFFFFF"
        android:textSize="15sp"/>
</LinearLayout>
Tomasz Mularczyk
  • 34,501
  • 19
  • 112
  • 166
  • Try getting reference to the textview which is not displayed. Then log the values of getX() and getY() method to find if they are positioned on the screen, and overlapped my some other views. – capt.swag Jun 19 '15 at 16:08

4 Answers4

0

you used 100dp android:layout_heightbut image and text are taller.

user3290180
  • 4,260
  • 9
  • 42
  • 77
0

You can try something like:

<LinearLayout
android:layout_width="100dp"
android:layout_height="wrap_content"
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android" >

<ImageView android:id="@+id/horizontal_list_image"
    android:layout_width="wrap_content"
    android:layout_height="0"
    android:weight="70"
    android:layout_gravity="center_horizontal" />

<TextView android:id="@+id/horizontal_list_text"
    android:layout_width="wrap_content"
    android:layout_height="0"
    android:weight="30"
    android:layout_gravity="center_horizontal"
    android:text="FFFFFFFF"
    android:textSize="15sp"/>

In that case the image will take 70% of the size and the textview will be the other 30%.

Franklin
  • 881
  • 1
  • 8
  • 28
0

Try to make RecyclerView item android:layout_height to match_parent instead of wrap_content

aelimill
  • 1,015
  • 1
  • 10
  • 17
  • then everything is gone. No image no text. – Tomasz Mularczyk Jun 19 '15 at 16:03
  • 1
    In case you want know the main reason try to go here http://stackoverflow.com/questions/26649406/nested-recycler-view-height-doesnt-wrap-its-content and take code from Kaerdan answer (setting his layout manager to RecyclerView) and setting recyclerview height to wrap_content . http://gyazo.com/422570986cf450ea7a254f01f1eb2069 – aelimill Jun 19 '15 at 16:50
  • so much workaround for such simple thing... I should have used `TwoWayListView`. – Tomasz Mularczyk Jun 19 '15 at 16:52
  • I'm using HorizontalListView (https://github.com/sephiroth74/HorizontalVariableListView) in my project – aelimill Jun 19 '15 at 16:54
0

This should work.

    <LinearLayout
    android:weightSum="2"

    android:layout_width="100dp"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    xmlns:android="http://schemas.android.com/apk/res/android" >

    <ImageView 
        android:layout_weight="1"

        android:id="@+id/horizontal_list_image"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal" />

    <TextView 
       android:layout_weight="1" 

        android:id="@+id/horizontal_list_text"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:text="FFFFFFFF"
        android:textSize="15sp"/>
</LinearLayout>
Prabhuraj
  • 928
  • 2
  • 8
  • 14