Sudarshan
Sudarshan

Reputation: 18554

Separator for a two column List view not working in Android

I want to separate data of two columns in a List View by a line or any block, as shown here

Need Separator as shown here

I tried following solutions, unfortunately they did not work

Solution 1

Solution 2


Please check code for my application and correct me if i missed any thing

Main Activity XML

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="fill_parent" android:layout_height="fill_parent" tools:context=".Time" android:background="@color/accent_material_dark" android:orientation="horizontal">
    <TextClock android:layout_width="fill_parent" android:layout_height="wrap_content" android:id="@+id/textClock" android:layout_gravity="center_vertical" android:format24Hour="@android:string/yes" />
</LinearLayout>

Row Layout XML

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout android:orientation="horizontal" android:layout_height="fill_parent" android:layout_width="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android">
    <TextView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/rowTextView1" style="@style/clock1"></TextView>
    <TextView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/rowTextView2" style="@style/clock2"></TextView>
</RelativeLayout>

Styles XML

<resources>
    <!-- Clock application theme. -->
    <style name="clock1">
        <!-- Customize your theme here. -->
        <item name="android:background">#24598a</item>
        <item name="android:padding">10dp</item>
        <item name="android:textSize">16sp</item>
        <item name="android:layout_width">match_parent</item>
        <item name="android:layout_height">wrap_content</item>
        <item name="android:layout_alignParentLeft">true</item>
    </style>
    <style name="clock2">
        <!-- Customize your theme here. -->
        <item name="android:background">#24598a</item>
        <item name="android:padding">10dp</item>
        <item name="android:textSize">16sp</item>
        <item name="android:layout_width">wrap_content</item>
        <item name="android:layout_height">wrap_content</item>
        <item name="android:layout_alignParentRight">true</item>
    </style>
    <style name="AppTheme" parent="android:style/Theme.Holo.Light.DarkActionBar"></style>
</resources>

Upvotes: 0

Views: 714

Answers (1)

Liran Peretz
Liran Peretz

Reputation: 580

try this example layout code for your list item view

<?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="50dp"
    android:background="@color/white"
    android:orientation="vertical" >

    <TextView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_toLeftOf="@+id/divider"
        android:gravity="left|center_vertical"
        android:text="Some data info" />

    <View
        android:id="@+id/divider"
        android:layout_width="1dp"
        android:layout_height="match_parent"
        android:layout_toLeftOf="@+id/clockInfo"
        android:background="@android:color/black" />

    <TextView
        android:id="@+id/clockInfo"
        android:layout_width="60dp"
        android:layout_height="match_parent"
        android:layout_alignParentRight="true"
        android:gravity="center"
        android:text="11:11" />

</RelativeLayout>

Upvotes: 1

Related Questions