您的位置:首页 > 其它

巧设置ExpandableListView右边的箭头

2015-09-21 17:16 411 查看
转载

1、更换ExpandableListView右边的箭头(小图标)的疑问

      第一个方法: 网上许多说到在ExpandableListView的布局xml中的groupIndicator更换成@drawable/***,我试过,可行,代码如下:

首先在drawable的文件夹下建立自定义选择布局属性的xml文件:ex_smallimage.xml

[html] view
plaincopyprint?





<span style="color:#666666;background-color: rgb(255, 255, 255);"><?xml version="1.0" encoding="UTF-8"?>  

<selector xmlns:android="http://schemas.android.com/apk/res/android">  

    <item android:state_expanded="false"  

          android:drawingCacheQuality="auto"  

        android:drawable="@drawable/la"/>     这里la是下拉图标  

    <item android:state_expanded="true"  

        android:drawingCacheQuality="auto"  

     android:drawable="@drawable/shou"/> 这里shou是收回图标  

</selector></span>  

然后在ExpandableListView的groupIndicator设为:                       android:groupIndicator="@drawable/ex_smallimage"

这样做了可行,但是有个问题,就是图标总是随group的大小而拉伸,不会缩放:

那么我调了xml的group代码之后,可以勉强达到自己要求的效果,但是这样的代码没有弹性,换张图片还得改布局。。。如果有知道如何设置图标的大小告诉我咯~呵呵。。

方法二:经过上面的尝试,我禁掉了groupIndicator属性,然后再在group的xml中加入ImageView,这样可以控制我的图片的缩放和位置的更改,代码:

android:groupIndicator="@null"这里非常重要,禁用系统自带的图标

再在group的xml中设置ImageView,这个简单,然后在适配器的getGroupView中加入图片变换的效果:

[html] view
plaincopyprint?





public View getGroupView(int groupPosition, boolean isExpanded,  

   View convertView, ViewGroup parent) {  

     // TODO Auto-generated method stub  

……   

           ImageView mgroupimage=(ImageView)convertView.findViewById(R.id.mGroupimage);  

           mgroupimage.setImageBitmap(mla);  

           if(!isExpanded){  

                  mgroupimage.setImageBitmap(mshou);  

            }  

……  

}  

OK,搞定它:

转载自:http://hi.baidu.com/%C1%D6%B5t%B3%CE01/blog/item/5186f1f9d23c8e72024f5617.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: