首页 > 其他 > 详细

expandableListView 总结

时间:2014-04-19 09:27:10      阅读:1045      评论:0      收藏:0      [点我收藏+]


实现效果图:

bubuko.com,布布扣

expandableListView  groupIndicator 图片默认是在左边,而且比较难看,而我要的是实现groupIndicator 在右边自定义图片,


  1. 换图片


最简单的就是直接copy 系统


<style name="Widget.ExpandableListView" parent="Widget.ListView">

      <item name="android:groupIndicator">@android:drawable/expander_group</item>

       <item name="android:indicatorLeft">?android:attr/expandableListPreferredItemIndicatorLeft</item>

       <item name="android:indicatorRight">?android:attr/expandableListPreferredItemIndicatorRight</item>

       <item name="android:childDivider">@android:drawable/divider_horizontal_dark_opaque</item>

   </style>


看到这个没有

<item name="android:groupIndicator">@android:drawable/expander_group</item>

我们只要把这个给换了,那 groupIndicator也就跟着变了。但是改这个有个问题显示出来的

显示的效果不是很好,图片有被拉升过,系统自己是做了个.9图片。我们已可以

2.做一张.9图片

   在你eclipse 的解压目录下,找到\sdk\tools\

我的是D:\android-IDE-eclipse-64\adt-bundle-windows-x86-20130522\sdk\tools

在这个目录下有一个draw9patch.bat的批处理文件。我们要用它做.9图,双击直接打开。直接将你要做成.9 的原图直接拉进工具。

3.创建 Indicator selector expander_group.xml 文件

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

   <item

       android:state_expanded="true"

       android:drawable="@drawable/up" />

   <item

       android:drawable="@drawable/down" />

</selector>

4.放一张图片到你的res目录下这里我直接用系统的

<item name="android:childDivider">@android:drawable/divider_horizontal_dark_opaque</item>

这个是一张图片

5.在自己的style。xml里写一个


 <style name="ExpandableListView" parent="android:Widget.ListView">

       <item name="android:groupIndicator">@drawable/expander_group</item>

       <item name="android:indicatorLeft">?android:attr/expandableListPreferredItemIndicatorLeft</item>

       <item name="android:indicatorRight">?android:attr/expandableListPreferredItemIndicatorRight</item>

       <item name="android:childDivider">@drawable/divider_horizontal_dark_opaque</item>

   </style>


这样我们就自己定义好了expandable的style

6.加载自己的style

   <ExpandableListView

       android:id="@+id/expandableListView1"

       style="@style/ExpandableListView"

       android:layout_width="match_parent"

       android:layout_height="match_parent"

       android:layout_alignParentLeft="true"

       android:layout_alignParentTop="true" >

   </ExpandableListView>

7.在activity中设置 Indicator位置

expandablelistView 提供一个方法设置位置

Display dp = getWindowManager().getDefaultDisplay();

int width = dp.getWidth();

lv.setIndicatorBounds(width-50, width);


运行完结果:

bubuko.com,布布扣

但又要实现title图片不回被拉伸放大,这样的效果就不是封好了,只能把图标给屏蔽了,然后在groupItem的布局加一个ImageView,用ImageView来标识。


   <ExpandableListView

       android:id="@+id/exlv_select_binddev"

       android:layout_width="match_parent"

       android:layout_height="match_parent"

       android:groupIndicator="@null"

       android:childIndicator="@null"

        >

   </ExpandableListView>


这样就把他给屏蔽了



本文出自 “android随记” 博客,请务必保留此出处http://xuxiong3316.blog.51cto.com/8126857/1398060

expandableListView 总结,布布扣,bubuko.com

expandableListView 总结

原文:http://xuxiong3316.blog.51cto.com/8126857/1398060

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!