设为首页 加入收藏

TOP

Android ExpandableListView的技巧和问题(一)
2017-10-13 10:30:47 】 浏览:5373
Tags:Android ExpandableListView 技巧 问题

前言:

最近一个多月在认真的学习Android和做项目,文章内容表达的不好或者理解错了,希望大家评论指出。 :-)

本文是总结几个比较常用且使用的技巧,和一个大家都会遇到的问题。

 

文章中大部分语句摘抄自一下两篇大神写的文章:(如果对ExpandableListView一无所知,建议按照顺序去阅读,遇到问题再看本文)

1、Android中ExpandableListView的使用

网址:http://blog.csdn.net/gyflyx/article/details/6461242

2、[Android UI设计]ExpandableListView详解

网址:http://www.tuicool.com/articles/JjaMnqf 

 

ExpandableListView是Android中可以实现下拉ListView的一个控件,是ListView的子类。

直接上图,就是这么一功能~

(点击就会展开,再点击就缩回去)

Android自带的布局不是这样的,这个是自定义了Group和Child的布局。

 

ExpandableListView的使用步骤:
1、在xml中定义一个ExpandableListView
2、在类中定义两个List集合,用于存放Group/Child中的内容,并初始化内容
3、定义ExpandableListView的Adapter,继承BaseExpanableListAdapter
例如:public class MyExpandableAdapter extends BaseExpandableListAdapter
4、最后给定义好的ExpandableView添加上Adapter

 

这里就贴出两个子布局的代码和MyExpandableAdapter的代码~

expandlist_group.xml

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

    <RelativeLayout android:layout_width="match_parent" android:layout_height="55dp" android:background="#d1d1d1" android:layout_marginTop="15dp">

        <TextView android:id="@+id/tv_group_name" android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_marginLeft="30dp" android:text="小猫" android:textColor="#ffffff" android:textSize="20sp" android:gravity="center_vertical"/>


        <ImageView android:id="@+id/iv_arrow" android:layout_width="25dp" android:layout_height="25dp" android:layout_alignParentRight="true" android:layout_centerVertical="true" android:layout_marginRight="20dp" android:background="@drawable/right_arrow"/>

    </RelativeLayout>



</LinearLayout>

 

expandlist_item.xml

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

    <RelativeLayout android:layout_width="match_parent" android:layout_height="45dp" android:layout_marginLeft="10dp" android:layout_marginRight="10dp" android:background="#b3b3b3">

        <TextView android:id="@+id/tv_child_name" android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_marginLeft="30dp" android:text="声音1" android:textColor="#ffffff" android:textSize="20sp" android:gravity="center_vertical"/>


        <ImageView android:id="@+id/iv_sound" android:layout_width="25dp" android:layout_height="25dp" android:layout_a
首页 上一页 1 2 3 下一页 尾页 1/3/3
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇Kotlin从入门到掉坑里 下一篇三行代码实现白天夜间模式流畅切..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目