这个东西用法基本固定,不知道能不能做三级的展开。

界面代码

<?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)
}
}

最新文章

  1. bootstrap-table分页第二篇 延续上一篇的
  2. 使用脚本自动配置matlab安装libsvm和随机森林工具箱
  3. 【原创】express3.4.8源码解析之中间件
  4. 【mybatis】之批量添加
  5. bzoj1043
  6. POJ2429 - GCD &amp; LCM Inverse(Miller&ndash;Rabin+Pollard's rho)
  7. 日期选择器——java
  8. CF R303 div2 C. Woodcutters
  9. 词典 (noi OpenJudge)
  10. KsUML 免费的类图建模工具
  11. Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column &#39;userinfo.
  12. python 第三方库 dateutil.parser 使用说明
  13. .NET/C# 资源
  14. Luogu P2403 [SDOI2010]所驼门王的宝藏
  15. 在 xilinx SDK 使用 math.h
  16. Win32 消息响应顺序
  17. 用monit监控系统关键进程
  18. linux 串口 特殊字符
  19. TClientDataSet数据源设置
  20. 关于Socket通讯中的Close_wait状态

热门文章

  1. ISCC之msc2
  2. 使用CIFAR-10样本数据集测试卷积神经网络(ConvolutionalNeuralNetwork,CNN)
  3. linux系统编程之信号(四)
  4. c++ default关键字
  5. tensorflow 与cuda、cudnn的对应版本关系
  6. WSGI原理
  7. BeautifulSoup模板简单应用-提取html指定数据(api_name/api_method/api_path,请求body/请求header/pagam参数)
  8. 自定义mvc增删改查
  9. 【概率论】6-1:大样本介绍(Large Random Samples Introduction)
  10. OpenFOAM制作动画