Android Studio初学笔记-Day25-ExpandableListVIew(1)

ExpandableListView

这是一个我个人认为稍微进阶的列表,因为它多了包覆一层的效果,不过这也是个常出现的元件,虽然稍微复杂了一点,不过整体还是很好理解的,不过它的篇幅有点长我将分成两篇来介绍,今天先来介绍它介面的配置还有资料的设定。

activity_main.xml

<LinearLayout 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"
    tools:context=".MainActivity">

    <ExpandableListView
        android:id="@+id/ep1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:childDivider="#2196F3"/>
</LinearLayout>
  • 首先在activity_main.xml档中加入ExpandableListView,在ExpandableListView的属性部分还有许多可以设定,这里我只用了子类别的分隔线的部分,值的部分直接输入需要颜色的色码即可,其他的可以参考官方文件,大部分都是对指标(展开列表旁的箭头)的细微或客制化调整。

接着可以再res/layout的资料夹中分别新增两个新的layout,一个负责组的部分,另一个负责子类别的部分。

language_title.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <TextView
        android:id="@+id/title_name"
        android:layout_width="match_parent"
        android:layout_height="30dp"
        android:gravity="center_vertical"
        android:paddingLeft="30dp"
        android:text="TextView"
        android:textStyle="bold"
        android:textSize="20sp" />

</LinearLayout>

language_content.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <TextView
        android:id="@+id/content_name"
        android:layout_width="match_parent"
        android:layout_height="30dp"
        android:gravity="center_vertical|center"
        android:text="TextView"
        android:textSize="20sp" />

</LinearLayout>

在同MainActivity.java的资料夹中新增两个java档来负责设定组和子类别的资料,简单设计如下。

Group.java

public class Group {
    private String name;

    public Group() {
    }
    public Group (String name){
        this.name = name;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
}

Content.java

public class Content {
    private String name;
    public Content() {
    }
    public Content (String name){
        this.name=name;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
}
  • 这两个负责之後关於ExpandableListView内资料的设定,这里只是简单设定一个String而已,可以依自己的需求改变。
    今天就先简单点题一下,完成这些前置作业,接下来的才是重头戏。虽然这些还只是摸到ExpandableListView的边,不过接下来的我希望用完整的一个新篇幅接续讲解,我们明天见。/images/emoticon/emoticon08.gif

<<:  Day 30 JavaScript < 简易数据类型介绍 & End>

>>:  D30 - 用 Swift 和公开资讯,打造投资理财的 Apps { 台股申购功能扩充,算出价差 }

D21 - 用 Swift 和公开资讯,打造投资理财的 Apps { 台股成交量实作.1 }

在技术分析,或是筹码分析的流派中,其中有流派是会用成交量和 K 线一起看,然後进行股票进出的判断。 ...

【Day11】忙得团团转的回圈

回圈指的是「重复做某件事,次数随着数值『递增」或『递减』,当数值满足所设的条件,则退出回圈」。 所...

26. 从学生社团到技术社群 x Girls in Tech x 曼陀号计画

曼陀号领航计画:Girls In Tech 主办的职涯成长计画。此计画所有人员皆以志工形式参与,为期...

Day05 - 使用 Link 实作换页

Link 在了解了 Next.js 的三种路由方式後,接下来就让我们来聊聊怎麽在 component...

Day 28 - 如何降低网站的安全性风险

出於书本 Chapter 14. Web sites and Application 使用隐匿性安全...