现在的位置: 首页 > 综合 > 正文

android 2级listview的实现

2013年05月02日 ⁄ 综合 ⁄ 共 1589字 ⁄ 字号 评论关闭

android开发中,会遇见分类下面还有小分类的情况,这个可以很简单的用ExpandableListView来实现.

截图如下:

实现代码:主界面,main.java

适配器:AllAdpter

xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:background="#EBEBEB"
    >
<TextView
     android:gravity="center_vertical"
    android:paddingLeft="25dp"
    android:textColor="#000000"
    android:layout_width="fill_parent"
    android:layout_height="45dp"
    android:textSize="16sp"
    android:id="@+id/all_list_text_item_id"
    />
</LinearLayout>

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >
    
<TextView
    android:gravity="center_vertical"
    android:textColor="#000000"
    android:paddingLeft="3dp"
    android:layout_width="fill_parent"
    android:layout_height="35dp"
    android:textSize="20sp"
    android:id="@+id/all_list_text_id"
    />
</LinearLayout>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#ffffff"
     >

   <ExpandableListView
        android:paddingLeft="3dp"
        android:cacheColorHint="#00000000"
        android:groupIndicator="@null"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:id="@+id/all"
        />
</RelativeLayout>

【上篇】
【下篇】

抱歉!评论已关闭.