0

I am displaying some items in a RecyclerView. In the layout of each item, I want a vertical bar to appear. I created an ImageView in the item layout. It is seen OK in the Design preview tab, but it is not seen in the device.

I have seen this question, similar to mine, but anything of that is working.

This is the layout (The testing device is a Samsung):

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="@+id/mainrl">

<ImageView
    android:layout_width="3dp"
    android:layout_height="match_parent"
    android:background="@color/backcolor"
    android:layout_marginStart="50dp"
    android:id="@+id/verticalbar"/>



<android.support.v7.widget.CardView
    android:layout_width="60dp"
    android:layout_height="60dp"
    android:id="@+id/daycv"
    android:layout_alignParentStart="true"
    android:layout_alignParentTop="true"
    android:layout_marginStart="20dp"
    android:layout_marginTop="10dp"
    card_view:cardCornerRadius="30dp"
    card_view:cardPreventCornerOverlap="false"
    card_view:cardBackgroundColor="@color/backcolor">

    <RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="match_parent">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/day"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="5dp"
            android:textColor="@color/white"
            android:textSize="17sp"/>

        <ImageView
            android:layout_width="match_parent"
            android:layout_height="1dp"
            android:layout_below="@+id/day"
            android:background="@color/white"
            android:id="@+id/separador"
            android:layout_marginStart="3dp"
            android:layout_marginEnd="3dp"
            android:layout_centerVertical="true"/>

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/month"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="5dp"
            android:layout_below="@+id/separador"
            android:textColor="@color/white"/>
    </RelativeLayout>
</android.support.v7.widget.CardView>

<android.support.v7.widget.CardView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@color/colorPrimary"
    android:layout_toEndOf="@+id/daycv"
    android:layout_alignTop="@+id/daycv"
    android:layout_marginEnd="10dp"
    android:layout_marginStart="10dp"
    android:id="@+id/contentcv">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/rl">

        <ImageView
            android:layout_width="match_parent"
            android:layout_height="200dp"
            android:id="@+id/image"/>

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:alpha="150"
            android:background="@color/gris">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/origen"
                android:layout_alignParentStart="true"
                android:layout_centerVertical="true"
                android:layout_marginStart="10dp"/>

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/flecha"
                android:layout_toEndOf="@+id/origen"
                android:layout_centerVertical="true"
                android:layout_marginStart="10dp"
                android:background="@android:drawable/ic_media_ff"/>

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/destino"
                android:layout_toEndOf="@+id/flecha"
                android:layout_marginStart="10dp"
                android:layout_centerVertical="true"/>


        </RelativeLayout>

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="60dp"
            android:layout_alignParentBottom="true"
            android:alpha="150"
            android:background="@color/gris">

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerVertical="true"
                android:id="@+id/voidimage"/>

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/fechasalida"
                android:layout_above="@+id/voidimage"
                android:layout_alignParentStart="true"
                android:layout_marginStart="10dp"/>

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/fechallegada"
                android:layout_alignStart="@+id/fechasalida"
                android:layout_below="@+id/voidimage"
                android:layout_marginBottom="10dp"/>

        </RelativeLayout>


    </RelativeLayout>
</android.support.v7.widget.CardView>

</RelativeLayout>

Why is my ImageView not been seen in device?

Thank you.

EDIT:

Image:

Image here

EDIT 2:

I have changed my layout to this:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="@+id/mainrl">



<RelativeLayout
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:id="@+id/cvrl">

    <!--<android.support.v7.widget.CardView
        android:layout_width="60dp"
        android:layout_height="60dp"
        android:id="@+id/daycv"
        android:layout_alignParentStart="true"
        android:layout_alignParentTop="true"
        android:layout_marginStart="20dp"
        android:layout_marginTop="10dp"
        card_view:cardCornerRadius="30dp"
        card_view:cardPreventCornerOverlap="false"
        card_view:cardBackgroundColor="@color/backcolor">-->

    <android.support.v7.widget.CardView
        android:layout_width="60dp"
        android:layout_height="60dp"
        android:id="@+id/daycv"
        android:layout_centerHorizontal="true"
        android:layout_marginStart="20dp"
        android:layout_marginTop="10dp"
        card_view:cardCornerRadius="30dp"
        card_view:cardPreventCornerOverlap="false"
        card_view:cardBackgroundColor="@color/backcolor">



        <RelativeLayout
            android:layout_width="wrap_content"
            android:layout_height="match_parent">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/day"
                android:layout_centerHorizontal="true"
                android:layout_marginTop="5dp"
                android:textColor="@color/white"
                android:textSize="17sp"/>

            <ImageView
                android:layout_width="match_parent"
                android:layout_height="1dp"
                android:layout_below="@+id/day"
                android:background="@color/white"
                android:id="@+id/separador"
                android:layout_marginStart="3dp"
                android:layout_marginEnd="3dp"
                android:layout_centerVertical="true"/>

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/month"
                android:layout_centerHorizontal="true"
                android:layout_marginTop="5dp"
                android:layout_below="@+id/separador"
                android:textColor="@color/white"/>
        </RelativeLayout>
    </android.support.v7.widget.CardView>

    <ImageView
        android:layout_width="3dp"
        android:layout_height="wrap_content" <---- Changing this affects how the vertical line sees. 
        android:src="@color/backcolor"
        android:layout_marginStart="40dp"
        android:layout_alignParentTop="true"
        android:layout_alignParentBottom="true"
        android:id="@+id/verticalbar"/>


</RelativeLayout>





<android.support.v7.widget.CardView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@color/colorPrimary"
    android:layout_toEndOf="@+id/cvrl"
    android:layout_alignTop="@+id/cvrl"
    android:layout_marginEnd="10dp"
    android:layout_marginStart="10dp"
    android:id="@+id/contentcv">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/rl">

        <ImageView
            android:layout_width="match_parent"
            android:layout_height="200dp"
            android:id="@+id/image"/>

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:alpha="150"
            android:background="@color/gris">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/origen"
                android:layout_alignParentStart="true"
                android:layout_centerVertical="true"
                android:layout_marginStart="10dp"/>

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/flecha"
                android:layout_toEndOf="@+id/origen"
                android:layout_centerVertical="true"
                android:layout_marginStart="10dp"
                android:background="@android:drawable/ic_media_ff"/>

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/destino"
                android:layout_toEndOf="@+id/flecha"
                android:layout_marginStart="10dp"
                android:layout_centerVertical="true"/>


        </RelativeLayout>

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="60dp"
            android:layout_alignParentBottom="true"
            android:alpha="150"
            android:background="@color/gris">

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerVertical="true"
                android:id="@+id/voidimage"/>

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/fechasalida"
                android:layout_above="@+id/voidimage"
                android:layout_alignParentStart="true"
                android:layout_marginStart="10dp"/>

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/fechallegada"
                android:layout_alignStart="@+id/fechasalida"
                android:layout_below="@+id/voidimage"
                android:layout_marginBottom="10dp"/>

        </RelativeLayout>


    </RelativeLayout>
</android.support.v7.widget.CardView>

</RelativeLayout>

If I put height: match_parent, only a bit of the line is seen. but, if I set to a random number (300dp, for example) the line is shown...

Fustigador
  • 6,339
  • 12
  • 59
  • 115

3 Answers3

0

Seems you're using ImageView incorrectly, I see you're trying to set the source using android:background prop, but the correct way to set the resource is using the prop android:src ,

For example

<ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/flecha"
                android:layout_toEndOf="@+id/origen"
                android:layout_centerVertical="true"
                android:layout_marginStart="10dp"
                android:src="@mipmap/ic_media_ff"/>
0

After struggling a while, and not knowing exactly why it was not working before, I manage to get it working by doing it this way:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="@+id/mainrl">



<RelativeLayout
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:id="@+id/cvrl"
    android:layout_alignBottom="@+id/rl2"
    android:layout_alignParentTop="true">


    <android.support.v7.widget.CardView
        android:layout_width="60dp"
        android:layout_height="60dp"
        android:id="@+id/daycv"
        android:layout_centerHorizontal="true"
        android:layout_marginStart="20dp"
        android:layout_marginTop="10dp"
        card_view:cardCornerRadius="30dp"
        card_view:cardPreventCornerOverlap="false"
        card_view:cardBackgroundColor="@color/backcolor">



        <RelativeLayout
            android:layout_width="wrap_content"
            android:layout_height="match_parent">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/day"
                android:layout_centerHorizontal="true"
                android:layout_marginTop="5dp"
                android:textColor="@color/white"
                android:textSize="17sp"/>

            <ImageView
                android:layout_width="match_parent"
                android:layout_height="1dp"
                android:layout_below="@+id/day"
                android:background="@color/white"
                android:id="@+id/separador"
                android:layout_marginStart="3dp"
                android:layout_marginEnd="3dp"
                android:layout_centerVertical="true"/>

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/month"
                android:layout_centerHorizontal="true"
                android:layout_marginTop="5dp"
                android:layout_below="@+id/separador"
                android:textColor="@color/white"/>
        </RelativeLayout>
    </android.support.v7.widget.CardView>

    <ImageView
        android:layout_width="3dp"
        android:layout_height="match_parent"
        android:src="@color/backcolor"
        android:layout_marginStart="40dp"
        android:id="@+id/verticalbar"
        android:layout_alignParentTop="true"
        android:layout_alignParentBottom="true"/>

</RelativeLayout>



<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/rl2"
    android:layout_alignParentEnd="true"
    android:layout_toEndOf="@id/cvrl"
    android:layout_marginEnd="10dp"
    android:layout_marginStart="10dp">

    <android.support.v7.widget.CardView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/colorPrimary"
        android:id="@+id/contentcv">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/rl">

            <ImageView
                android:layout_width="match_parent"
                android:layout_height="200dp"
                android:id="@+id/image"/>

            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_alignParentTop="true"
                android:alpha="150"
                android:background="@color/gris">

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:id="@+id/origen"
                    android:layout_alignParentStart="true"
                    android:layout_centerVertical="true"
                    android:layout_marginStart="10dp"/>

                <ImageView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:id="@+id/flecha"
                    android:layout_toEndOf="@+id/origen"
                    android:layout_centerVertical="true"
                    android:layout_marginStart="10dp"
                    android:background="@android:drawable/ic_media_ff"/>

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:id="@+id/destino"
                    android:layout_toEndOf="@+id/flecha"
                    android:layout_marginStart="10dp"
                    android:layout_centerVertical="true"/>


            </RelativeLayout>

            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="60dp"
                android:layout_alignParentBottom="true"
                android:alpha="150"
                android:background="@color/gris">

                <ImageView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_centerVertical="true"
                    android:id="@+id/voidimage"/>

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:id="@+id/fechasalida"
                    android:layout_above="@+id/voidimage"
                    android:layout_alignParentStart="true"
                    android:layout_marginStart="10dp"/>

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:id="@+id/fechallegada"
                    android:layout_alignStart="@+id/fechasalida"
                    android:layout_below="@+id/voidimage"
                    android:layout_marginBottom="10dp"/>

            </RelativeLayout>


        </RelativeLayout>
    </android.support.v7.widget.CardView>
</RelativeLayout>



</RelativeLayout>
Fustigador
  • 6,339
  • 12
  • 59
  • 115
0

Your mother Relativelayout height is wrap_content

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="@+id/mainrl">

change to

android:layout_height="match_parent"

And if you just want to display a vertical line, use View with a background instead of ImageView

Turvy
  • 882
  • 1
  • 8
  • 23
  • That would cause each item in the RecyclerView occupy the whole screen, I don't want that. Anyway, I solved this. Thank you. – Fustigador Jun 24 '19 at 15:32