ExpandableListView添加头布局和尾部局

ExpandableListView是什么?

ExpandableListView时一种可折叠的下拉列表,就像之前QQ好友分组的控件。

ExpandableListView怎么用?

它和ListView的用法差不多,写Adapter时继承的是BaseExpandableListAdapter,重写里边的方法。

ExpandableListView添加头布局和尾部局?

不知道大家看过ListView添加头布局和尾部局的方法没,其实ExpandableListView的添加方法和ListView的添加方法是一样的,下面详细说明:

1.ExpandableListView可以展示后,新建一个shopping_footer_layout.xml布局,讲布局设置好,如果只有一个控件,它可以直接设置为根部局。

<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/tv_footer"
    android:layout_width="match_parent"
    android:layout_height="60dp"
    android:background="@color/aliceblue"
    android:text="---随便逛逛---"
    android:gravity="center"
    android:clickable="true"
    >
</TextView>

2.在Activity中实例化。

//exListView的尾部局
    private TextView tv_footer;
    tv_footer = (TextView) LayoutInflater.from(this).inflate(R.layout.shopping_footer_layout, null);
3.添加头尾布局,ListView是在Adapter设置之前添加,ExpandableListView我试验了,在Adapter之前或之后添加都可以。

//添加尾部局
        exListView.addFooterView(tv_footer);
//或者添加头布局
        exListView.addHeaderView(tv_footer);
4.给头布局/尾部局设置点击事件,跟正常的一样。
 tv_footer.setOnClickListener(this);

出现的问题

无论你怎样改shopping_footer_layout.xml中的高度,运行出来随便逛逛那部分的高度不变,但是这部分又要宽一点,我想到了另一种方法,在TextView中加一个padding属性

多高自己随便改。

<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/tv_footer"
    android:layout_width="match_parent"
    android:layout_height="60dp"
    android:background="@color/aliceblue"
    android:text="---随便逛逛---"
    android:gravity="center"
    android:clickable="true"
    android:padding="30dp"
    >



  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值