expandablelistView 可展开的列表

这个东西用法基本固定,不知道能不能做三级的展开。
界面代码
<?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="match_parent">
<ExpandableListView
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:childIndicator="@mipmap/ic_launcher"
android:childIndicatorStart="380dp"
android:childIndicatorEnd="410dp"/>
</LinearLayout>
主程序代码
package com.example.expandablelistview import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import android.view.Gravity
import android.view.View
import android.view.ViewGroup
import android.widget.* class MainActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main) val adapter = object:BaseExpandableListAdapter()
{
internal var logos = intArrayOf(R.drawable.p, R.drawable.z, R.drawable.t)
private val armTypes = arrayOf("神族兵种", "虫族兵种", "人族兵种")
private val arms = arrayOf(arrayOf("狂战士", "龙骑士", "黑暗圣堂", "电兵"),
arrayOf("小狗", "刺蛇", "飞龙", "自爆飞机"),
arrayOf("机枪兵", "护士MM", "幽灵"))
private val textView: TextView
get()
{
val textView = TextView(this@MainActivity)
val lp = AbsListView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT)
textView.layoutParams = lp
textView.gravity = Gravity.CENTER_VERTICAL or Gravity.START
textView.setPadding(36, 10, 0, 10)
textView.textSize = 20f
return textView
}
// 获取指定组位置、指定子列表项处的子列表项数据
override fun getChild(groupPosition: Int, childPosition: Int): Any
{
return arms[groupPosition][childPosition]
} override fun getChildId(groupPosition: Int, childPosition: Int): Long
{
return childPosition.toLong()
} override fun getChildrenCount(groupPosition: Int): Int
{
return arms[groupPosition].size
} // 该方法决定每个子选项的外观
override fun getChildView(groupPosition: Int, childPosition: Int,
isLastChild: Boolean, convertView: View?, parent: ViewGroup): View
{
val textView: TextView
if (convertView == null)
{
textView = this.textView
textView.text = getChild(groupPosition, childPosition).toString()
}
else
{
textView = convertView as TextView
}
return textView
} // 获取指定组位置处的组数据
override fun getGroup(groupPosition: Int): Any
{
return armTypes[groupPosition]
} override fun getGroupCount(): Int
{
return armTypes.size
} override fun getGroupId(groupPosition: Int): Long
{
return groupPosition.toLong()
} // 该方法决定每个组选项的外观
override fun getGroupView(groupPosition: Int, isExpanded: Boolean,
convertView: View?, parent: ViewGroup): View
{
val ll: LinearLayout
if (convertView == null)
{
ll = LinearLayout(this@MainActivity)
ll.orientation = LinearLayout.HORIZONTAL
val logo = ImageView(this@MainActivity)
logo.setImageResource(logos[groupPosition])
ll.addView(logo)
val textView = this.textView
textView.text = getGroup(groupPosition).toString()
ll.addView(textView)
}
else
{
ll = convertView as LinearLayout
}
return ll
} override fun isChildSelectable(groupPosition: Int, childPosition: Int): Boolean
{
return true
} override fun hasStableIds(): Boolean
{
return true
}
}
val expandListView = findViewById<ExpandableListView>(R.id.list)
expandListView.setAdapter(adapter)
}
}
expandablelistView 可展开的列表的更多相关文章
- 可展开的列表组件——ExpandableListView深入解析
可展开的列表组件--ExpandableListView深入解析 一.知识点 1.ExpandableListView常用XML属性 2.ExpandableListView继承BaseExpanda ...
- 【转】 HVTableView创建--展开/折叠列表能 AAShareBubbles社会分享动画组
原文: http://blog.csdn.net/billfanggs/article/details/17279969 HVTableView HVTableView是UITableView(带有展 ...
- android之ExpandableListView 无法展开
1.Button 对,没错,就是这个button组件,不知道出现都少次过问题,很多都是它造成的! 最常见的问题:ExpandableListView无法展开,OnItemClickListener不响 ...
- 微信小程序 - 展开收缩列表
代码源自于:微信小程序示例官方 index.wxml <block wx:for-items="{{list}}" wx:key="{{item.id}}" ...
- (转载)自定义ExpandableListView,实现二级列表效果
先看效果图: 上图是我们要实现的效果,那么现在我们开始着手去做,主要分为以下几步: 一丶我们需要根据效果图去思考该如何动手,从上图分析看,我们可以用一个相对布局RelativeLayout来完成gro ...
- 【深入篇】自定义ExpandableListView,实现二级列表效果
先看效果图: 上图是我们要实现的效果,那么现在我们开始着手去做,主要分为以下几步: 一丶我们需要根据效果图去思考该如何动手,从上图分析看,我们可以用一个相对布局RelativeLayout来完成gro ...
- Python代码阅读(第11篇):展开嵌套列表
Python 代码阅读合集介绍:为什么不推荐Python初学者直接看项目源码 本篇阅读的代码实现了展开嵌套列表的功能,将一个嵌套的list展开成一个一维list(不改变原有列表的顺序). 本篇阅读的代 ...
- ExpandableListView(可展开的列表组件)的说明以及其用法
ExpandableListView的用法和ListView非常像,只是其所显示的列表项应该由ExpandableListAdapter提供,下面是它的xml属性及说明: 然而,接下来是用事实说话了: ...
- ExpandableListView实现展开更多和收起更多
[需求]: 如上面图示 当点开某个一级菜单的时候,其他菜单收起: 子级菜单默认最多5个: 多于5个的显示"展开更多" 点击"展开更多",展开该级所有子级菜单,同 ...
随机推荐
- C++(三十七) — 字符串的函数重载—案例
1.MyString.h 头文件 #pragma once #include <iostream> using namespace std; class MyString { public ...
- 高并发下redis
1.================================================================================================== ...
- SQL进阶系列之2自连接
写在前面 一般地,SQL的连接运算根据其特征的不同,有着不同的名称,比如内连接.外连接.交叉连接等,这些连接大多是以不同的表或视图为对象进行的,针对相同的表进行的连接成为自连接.理解自连接有助于我们理 ...
- VMware Linux系统克隆
系统克隆 网卡设备无法识别 解决克隆虚拟机后网卡设备无法识别启动问题的方法 一.故障问题 从vmware workstation中克隆(clone)了一个CentOS 6的虚拟机,启动之后发现网卡没有 ...
- rest-framework频率组件、url注册器、响应器、分页器
频率组件 import time from rest_framework.throttling import BaseThrottle,SimpleRateThrottle IP_DICT = {} ...
- 适合于做项目与团队管理的工具(Choerodon)
官网链接:http://choerodon.io/zh/ 此处不做太多的介绍,需要了解的朋友进入官网进行查看. Choerodon猪齿鱼开源多云技术平台,是基于开源技术Kubernetes,Istio ...
- js 定时器 执行一次和重复执行
1- 执行一次(延时定时器) var t1 = window.setTimeout(function() { console.log('1秒钟之后执行了') },1000) window.clearT ...
- LightOJ - 1294 - Positive Negative Sign(规律)
链接: https://vjudge.net/problem/LightOJ-1294 题意: Given two integers: n and m and n is divisible by 2m ...
- 【洛谷P4245】 【模板】任意模数NTT
三模数 NTT,感觉不是很难写 $?$ 代码借鉴的 https://www.cnblogs.com/Mychael/p/9297652.html code: #include <bits/std ...
- cube.js 学习(八)backend部署模式
cube.js 从设计上就进行了系统上的分层,backend,frontend,backend 是cube.js 的核心 对于cube.js backend 的部署官方也提供了好多中方法 部署模型 s ...