Emil Adz
Emil Adz

Reputation: 41099

How to create custom listview for android with margins between 2 elements?

I need to create an application with a list-view activity, but the elements in the list should be separated one from another and have more then one click option:

Here is the image:

enter image description here

so i can click on the on the task to see the task details and i can click on the left side of the task (the colored part) to change it's color, and this way to change it's priority

i would really appreciate if some one could provide me with a tutorial or additional reading information to creating such custom lists.

Upvotes: 1

Views: 8836

Answers (4)

Shraddha Shravagi
Shraddha Shravagi

Reputation: 1146

I think you need to mention a shape.xml for each styling your row. And then in your row layout use an RelativeLayout for arranging the items. And make sure that you make the android:background="@android:color/transparent" for each button you create there. First one will be an ImageButton. enter image description here

This is what you can achieve. Let me know if this helps you.

Upvotes: 0

Swati
Swati

Reputation: 1179

<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp" >

<ImageView
    android:id="@+id/icon"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/ic_launcher" />

<TextView
    android:id="@+id/label"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Label" />

</LinearLayout>

You can use this as the layout for your list row in your list adapter. And you can acheive the spacing by increasing and decreasing the margin for the parent layout. Hope it will help you

Upvotes: 0

NaserShaikh
NaserShaikh

Reputation: 1576

You need to create a custom xml layout for list item. and in a listview give devider heght.. like i did here.

enter image description here

 <ListView
     android:id="@+id/lstContact"
     android:layout_width="fill_parent"
     android:layout_height="wrap_content"
     android:layout_below="@+id/lay"
     android:divider="#0000"
     android:dividerHeight="6dp"
     android:layout_marginTop="3dp"
     android:padding="5dp"
     android:background="#0000"
     android:cacheColorHint="#0000"
     android:scrollbars="none" />

Upvotes: 0

K_Anas
K_Anas

Reputation: 31466

divider and dividerHeight property of the ListView can make space between your listview items:

<ListView android:id="@+id/list_view"
  android:layout_height="fill_parent"
  android:layout_width="fill_parent"
  android:divider="@android:color/transparent"
  android:dividerHeight="10.0sp"/>

You can find some tutorial on how to build an Android Listview with Multiple Clickable Zones

Upvotes: 5

Related Questions