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

别等时光非礼了梦想. 提交于 2019-12-24 14:00:18

问题


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:

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.


回答1:


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




回答2:


You need to create a custom xml layout for list item. and in a listview give devider heght.. like i did 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" />



回答3:


<?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




回答4:


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.

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



来源:https://stackoverflow.com/questions/14345840/how-to-create-custom-listview-for-android-with-margins-between-2-elements

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!