Custom ListView Item Graphical Layout Android

被刻印的时光 ゝ 提交于 2019-12-10 13:56:43

问题


Please forgive my ignorance, but this is my 3rd day with Android, and I've looked at tutorials, and they all seem to focus on the xml declaration of listview item UI. My question is this, I'd like to be able to see the custom listview item UI in the designer "Graphical Layout" in Eclipse. However, it displays it just like it does any other view in Android, ie. with the title and status bar at the top and taking up the entire screen. What I'd like to see is just the listview item that I'm designing ie. just 50dp tall and filled width. Is there a way to do this?


回答1:


I believe what you are looking for is a custom adapter. What you are seeing is just the listview item, what you are looking for is the custom layout. Have a look at this tutorial, specifically the part on designing the custom layout and the custom adapter.

http://www.androidhive.info/2012/02/android-custom-listview-with-image-and-text/




回答2:


It's a general Layout example to make custom listview :

Main Activity Layout :

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <ListView
        android:id="@+id/list"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
     />
</LinearLayout>

ListView Row layout XML (list.xml) :

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >
    <ImageView
        android:id="@+id/icon"
        android:layout_width="80dp"
        android:layout_height="80dp"
        android:contentDescription="@string/image"
        android:paddingLeft="10dp"
        android:paddingRight="10dp" />

    <TextView
        android:id="@+id/title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_toRightOf="@+id/icon"
        android:paddingBottom="10dp"
        android:textColor="#CC0033"
        android:textSize="16dp" />

    <TextView
        android:id="@+id/desc"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/title"
        android:layout_toRightOf="@+id/icon"
        android:paddingLeft="10dp"
        android:textColor="#3399FF"
        android:textSize="14dp" />
</RelativeLayout>



回答3:


I think the only way to see what the listview will look like is to run the application on a device and fill the listview with test data. It's kind of a pain.



来源:https://stackoverflow.com/questions/13506763/custom-listview-item-graphical-layout-android

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