日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 运维知识 > Android >内容正文

Android

Android之ExpandableListView的各种效果(默认展开不合闭,自定义父栏目及箭头控制)

發(fā)布時間:2024/10/12 Android 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Android之ExpandableListView的各种效果(默认展开不合闭,自定义父栏目及箭头控制) 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

1. 設(shè)置ExpandableListView 默認(rèn)是展開的:?
  先實(shí)例化exListView (ExpandableListView所有數(shù)據(jù)齊全后可用,否則報錯)

exListView.setAdapter(exlvAdapter); //遍歷所有g(shù)roup,將所有項(xiàng)設(shè)置成默認(rèn)展開 intgroupCount = exListView.getCount(); for (inti=0; i<groupCount; i++) { exListView.expandGroup(i); };

?

2. 去掉ExpandableListView 默認(rèn)的箭頭?
  用到ExpandableListView時有個箭頭圖標(biāo)系統(tǒng)自帶的在你自定義布局也不能去掉只要設(shè)置一個屬性即可,如下:?

settingLists.setGroupIndicator(null);

?

此處就是設(shè)置自定義的箭頭圖標(biāo)的。置空則沒有了。 ?
也可以自定義(但是位置還是在那個地方不推薦)如下:?
首先,自定義一個expandablelistviewselector.xml文件,具體內(nèi)容如下: Java代碼?

加一句代碼如下:?

?

<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_expanded="true" android:drawable="@drawable/expandablelistviewindicatordown" /> <item android:drawable="@drawable/expandablelistviewindicator" /> </selector> settingLists.setGroupIndicator(this.getResources().getDrawable(R.layout.expandablelistviewselector)); ??或xml設(shè)置: ?android:groupIndicator="@drawable/groupIndicator_selector"

3. 將默認(rèn)的箭頭修改到右邊顯示:?
?
  1)首先ExpandableListViewelistview; ?

    elistview.setGroupIndicator(null);//將控件默認(rèn)的左邊箭頭去掉

?  2)在自定義的繼承自BaseExpandableListAdapter的adapter中有一個方法

/** * 父類view */ @Override ublic View getGroupView(intgroupPosition, booleanisExpanded, View convertView, ViewGroup parent) { Log.i("zhaoxiong","parent view"); LinearLayoutparentLayout=(LinearLayout) View.inflate(context, R.layout.wowocoupons_parent_item, null); TextViewparentTextView=(TextView)parentLayout.findViewById(R.id.parentitem); parentTextView.setText(parentlist.get(groupPosition)); ImageViewparentImageViw=(ImageView) parentLayout.findViewById(R.id.arrow); //判斷isExpanded就可以控制是按下還是關(guān)閉,同時更換圖片 if(isExpanded){ parentImageViw.setBackgroundResource(R.drawable.arrow_down); }else{ parentImageViw.setBackgroundResource(R.drawable.arrow_up); } return parentLayout; }

expandablelistview響應(yīng)onGroupClick監(jiān)聽:

設(shè)置expandablelistview.setOnGroupClickListener()
折疊和展開事件,可以設(shè)置setOnGroupCollapseListener和setOnGroupExpandListener

ExpandableListView中包含多個group,想要展開一個group時,其他group都關(guān)閉:

exList.setOnGroupExpandListener(new OnGroupExpandListener() { @Override public void onGroupExpand(int groupPosition) { for (int i = 0; i < getData().size(); i++) { if (groupPosition != i) { exList.collapseGroup(i); } } } });

3)expandablelistview的Group點(diǎn)擊事件,onGroupClick的返回值false展開,true不展開(如果配合默認(rèn)展開,就會固定展開不收縮)

按 Ctrl+C 復(fù)制代碼

總結(jié)

以上是生活随笔為你收集整理的Android之ExpandableListView的各种效果(默认展开不合闭,自定义父栏目及箭头控制)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。