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

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > Android >内容正文

Android

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

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

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

exListView.setAdapter(exlvAdapter); //遍歷所有group,將所有項設置成默認展開 intgroupCount = exListView.getCount(); for (inti=0; i<groupCount; i++) { exListView.expandGroup(i); };

?

2. 去掉ExpandableListView 默認的箭頭?
  用到ExpandableListView時有個箭頭圖標系統自帶的在你自定義布局也不能去掉只要設置一個屬性即可,如下:?

settingLists.setGroupIndicator(null);

?

此處就是設置自定義的箭頭圖標的。置空則沒有了。 ?
也可以自定義(但是位置還是在那個地方不推薦)如下:?
首先,自定義一個expandablelistviewselector.xml文件,具體內容如下: 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設置: ?android:groupIndicator="@drawable/groupIndicator_selector"

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

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

?  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就可以控制是按下還是關閉,同時更換圖片 if(isExpanded){ parentImageViw.setBackgroundResource(R.drawable.arrow_down); }else{ parentImageViw.setBackgroundResource(R.drawable.arrow_up); } return parentLayout; }

expandablelistview響應onGroupClick監聽:

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

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

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點擊事件,onGroupClick的返回值false展開,true不展開(如果配合默認展開,就會固定展開不收縮)

按 Ctrl+C 復制代碼

總結

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

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。