我想实现一个类似于 iPhone 形式的 ListView。

表格的第一个元素是图像,其他元素是文本加箭头。

我知道如何使用自定义图像适配器,但仅用于独特的自定义,而不是自定义每一行。

该信息是静态的,我应该只能单击所需的元素。

非常感谢你。

最佳答案

我找到了解决办法,

我可以使用 ListView 的标题和自定义边框。
下面是一个例子:

drawable 文件夹中的 listview_border.xml:

<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<stroke android:width="4dp" android:color="#FFFFFFFF" />
<padding android:left="7dp" android:top="7dp"
        android:right="7dp" android:bottom="7dp" />
<corners android:radius="15dp" />
<solid android:color="#FFFFFFFF"/>
</shape>

对于 ListView ,设置:
 android:background="@drawable/listview_border"

然后对于hedser,在布局中创建一个listviaw_header.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

   <ImageView
       android:id="@+id/imageView1"
       android:layout_width="128dp"
       android:layout_height="wrap_content"
       android:src="@drawable/contact_image_fr"
       android:layout_marginLeft="10dp" />

</LinearLayout>

然后设置标题:
ListView contact = (ListView) findViewById(R.id.contactListView);


    View header = getLayoutInflater().inflate(R.layout.contact_listview_header, null);

    contact.addHeaderView(header);

就这样。享受...

关于Android listView 作为 iPhone 的 listView,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/12239790/

10-11 22:43
查看更多