Android 之ExpandableListView几个特殊的属性

1. 设置ExpandableListView 默认是展开的: android

先实例化 exListView ide

而后 布局

   exListView.setAdapter(exlvAdapter); this

   //遍历全部group,将全部项设置成默认展开 spa

   int groupCount = exListView.getCount(); .net

   for (int i=0; i<groupCount; i++) { xml

       exListView.expandGroup(i); blog

       }; 继承


 

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)); 

大功告成

3. 将默认的箭头修改到右边显示:


1首先 ExpandableListView elistview;

         elistview.setGroupIndicator(null);//将控件默认的左边箭头去掉,

2在 自定义的继承自BaseExpandableListAdapter的adapter中有一个方法

/**
 * 父类view
 */
    @Override
    public View getGroupView(int groupPosition, boolean isExpanded,
            View convertView, ViewGroup parent) {
        Log.i("zhaoxiong","parent view");
            LinearLayout parentLayout=(LinearLayout) View.inflate(context, R.layout.wowocoupons_parent_item, null);
            TextView parentTextView=(TextView) parentLayout.findViewById(R.id.parentitem);
            parentTextView.setText(parentlist.get(groupPosition));
            ImageView parentImageViw=(ImageView) parentLayout.findViewById(R.id.arrow);

//判断isExpanded就能够控制是按下仍是关闭,同时更换图片
            if(isExpanded){                 parentImageViw.setBackgroundResource(R.drawable.arrow_down);             }else{                 parentImageViw.setBackgroundResource(R.drawable.arrow_up);             }                  return parentLayout;     }

相关文章
相关标签/搜索