0

I have a list item layout, and this layout is used in a StickyListHeaderListView and contains a vertical separator behind an image. The problem is that the view separator is never drawn on a real device despite being drawn on the preview screen.

Here is the xml layout code

<?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:layout_width="match_parent"
       android:layout_height="match_parent"
       android:minHeight="80dp"
       android:paddingLeft="@dimen/padding_medium"
       android:paddingRight="@dimen/padding_medium"
       tools:ignore="MissingPrefix">

<TextView
    android:id="@+id/textview_date"
    fontPath="@string/font_semi_bold"
    android:layout_width="wrap_content"
    android:maxWidth="60dp"
    android:layout_height="match_parent"
    android:layout_centerVertical="true"
    android:gravity="center_vertical|right"
    android:textAppearance="@android:style/TextAppearance.Holo.Medium"
    android:textColor="#999999"
    tools:text="21\nFeb" />

<RelativeLayout
    android:id="@+id/container"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_toRightOf="@+id/textview_date"
    android:minWidth="50dp"
    android:paddingLeft="@dimen/padding_extra_small"
    android:paddingRight="@dimen/padding_extra_small">

    <View
        android:layout_width="1px"
        android:layout_height="match_parent"
        android:layout_centerHorizontal="true"
        android:background="#999999" />
    <ImageView
        android:layout_width="40dp"
        android:layout_height="40dp"
        android:layout_alignParentTop="true"
        android:layout_marginTop="@dimen/margin_small"
        android:src="@drawable/test_event_cat_1" />
</RelativeLayout>

<TextView
    android:id="@+id/textview_event_name"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_toRightOf="@+id/container"
    android:layout_marginTop="@dimen/margin_small"
    android:textColor="#999999"
    fontPath="@string/font_medium"
    tools:text="ACS Nights’ Soccer Finale"
    android:textAppearance="@android:style/TextAppearance.Holo.Medium" />
<TextView
    android:id="@+id/textview_interval"
    android:layout_width="match_parent"
    android:textAppearance="@android:style/TextAppearance.Holo.Small"
    android:layout_alignLeft="@+id/textview_event_name"
    android:layout_below="@id/textview_event_name"
    android:layout_marginTop="@dimen/margin_small"
    android:textColor="#999999"
    tools:text="4:00 PM - 6:00 PM"
    android:layout_height="wrap_content" />
 </RelativeLayout>

This code generates a correct layout in the preview window of the Android Studio

Android Studio Preview Output

But the output on the device does not contain any vertical lines as in the preview

Device output

I tried putting the vertical line in different parts of the layout but still not shown on a real device. Any help would be appreciated.

Ahmed I. Khalil
  • 743
  • 6
  • 20

2 Answers2

0

How do you add a new item to your listView?

Does every item have the layout of the entire xml file?

So one row would use the entire layout.xml file?

EDIT:

I'm guessing that, since you have 2 views in your relative layout with the line, the image pushes the line off the screen. I took me a while to find some reference material, but here.

RelativeLayout works the same way, the last image in the relative layout wins.

So you'll have to find a way where either you draw the image on top of the line. Or you can draw a simple line as a drawable and set that as the background of your relativeLayout that contains the image

Community
  • 1
  • 1
Bart de Ruijter
  • 917
  • 10
  • 21
0

I changed root from RelativeLayout to a horizontal LinearLayout and after doing the necessary layout changes, the problem is solved now !

I've read somewhere that RelativeLayout whose parent is a ListView has problems when assigned with match_parent height.

Community
  • 1
  • 1
Ahmed I. Khalil
  • 743
  • 6
  • 20