1 . ExpandableListView布局:
<ExpandableListView  
  android:id="@+id/bbs_category_expandable_listview"
  android:divider="#c0c0c0"
  android:dividerHeight="1dip"
  android:childDivider="#c0c0c0"
  android:fadingEdgeLength="0dip"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:cacheColorHint="#00000000"
  android:scrollbars="none"
  android:listSelector="#00000000"/>
2 .ExpandableListView 父item布局:
里面的Imageview就是自定义的右边的箭头,这个位置可以随你需要自定义的
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/bbs_categrory_parent_list">
    <TextView
        android:id="@+id/bbs_category_group_listitem"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="10dip"
        android:text="14sp"
        android:textColor="#000000"
        android:layout_gravity="left|center_vertical"/>
     <ImageView 
        android:id="@+id/bbs_expandle_list_image"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="right|center_vertical"
        android:layout_marginRight="10dip"/>    
</FrameLayout>            
3. ExpandableListView 子item布局:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/bbs_categrory_children_list">
    <TextView
        android:id="@+id/bbs_children_list_item"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="10dip"
        android:layout_gravity="center_vertical"
        android:textSize="14sp"
        android:textColor="#777777"/>
</LinearLayout>

4.以下是Activity (l里面代码只是把expandablelistview相关代码贴出来了):
public class BbsCategoryListActivity extends BaseActivity {
private List<Forum> parentsForums=null;          //存放板块二级数据
private List<List<Forum>> childrenForums=null;   //存放板块三级数据
private List<Forum> forums;
private ExpandableListView expandablelistView; 
private ExpandableListViewAdapter adapter ;
private TextView searchResultText;
private TextView searchResultIsNullText;
private long forumIndex;
private LayoutInflater layoutInflater =null;
private BbsApiService bbsApiService ;
private String forumType=null;
public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);
setContentView(R.layout.bbs_category_list_activity);
expandablelistView = (ExpandableListView) this.findViewById(R.id.bbs_category_expandable_listview);
searchContent = (EditText) this.findViewById(R.id.bbs_search_keyword_field);
searchButton = (ImageButton) this.findViewById(R.id.bbs_forum_search_button);
backButton = (ImageButton) this.findViewById(R.id.bbs_category_listview_back);
searchResultText = (TextView) this.findViewById(R.id.bbs_category_searchresult_text);
searchResultIsNullText = (TextView) this.findViewById(R.id.bbs_category_searchresult_isnulltext);
searchResultText.setVisibility(View.GONE);
searchResultIsNullText.setVisibility(View.GONE);
     
     
    
adapter = new ExpandableListViewAdapter(this);
new HandleForumTread().start();
     
     
/**
* expandablelistView 三级数据点击事件
*/
expandablelistView.setOnChildClickListener(new OnChildClickListener() {
public boolean onChildClick(ExpandableListView parent, View v,
     int groupPosition, int childPosition, long id) {
if(childrenForums.size()>0 && groupPosition>=0 && groupPosition<childrenForums.size() && 
  childPosition>=0 && childPosition<childrenForums.get(groupPosition).size()){
     long pid = childrenForums.get(groupPosition).get(childPosition).getPid();
     String name = childrenForums.get(groupPosition).get(childPosition).getPname();
     String forumLogoUrl = childrenForums.get(groupPosition).get(childPosition).getLogo();
     if("favorite".equals(forumType)){//如果收藏板块
  BbsMainFavoriteActivity.forumId = pid;
  BbsMainFavoriteActivity.forumName = name;
  BbsMainFavoriteActivity.forumLogoUrl = forumLogoUrl;
  BbsMainFavoriteActivity.fromActivity="BbsCategoryListActivity";
  finish();
     }else{
  //传递数据到帖子列表页面
  Intent intent = new Intent(BbsCategoryListActivity.this,BbsTopicListActivity.class);
  intent.putExtra("childrenForumId", pid);
  intent.putExtra("forumName", name);
  intent.putExtra("forumLogoUrl", forumLogoUrl);
  startActivity(intent);
     }
}
return false;
}
});
     
     
     /**
         * expandablelistView 二级数据点击事件
         */
     expandablelistView.setOnGroupClickListener(new OnGroupClickListener() {
            public boolean onGroupClick(ExpandableListView parent, View v,int groupPosition, long id) {
                if(parentsForums.size()>0 && (parentsForums.get(groupPosition).getChildren()==null
                        || !(parentsForums.get(groupPosition).getChildren().size()>0))){
                    long pid = parentsForums.get(groupPosition).getPid();
                    String name = parentsForums.get(groupPosition).getPname();
                    String forumLogoUrl = parentsForums.get(groupPosition).getLogo();
                    if("favorite".equals(forumType)){//如果收藏板块
                        BbsMainFavoriteActivity.forumId = pid;
                        BbsMainFavoriteActivity.forumName = name;
                        BbsMainFavoriteActivity.forumLogoUrl = forumLogoUrl;
                        BbsMainFavoriteActivity.fromActivity="BbsCategoryListActivity";
                        finish();
                    }else{
                        //传递数据到帖子列表页面
                        Intent intent = new Intent(BbsCategoryListActivity.this,BbsTopicListActivity.class);
                        intent.putExtra("childrenForumId", pid);
                        intent.putExtra("forumName", name);
                        intent.putExtra("forumLogoUrl", forumLogoUrl);
                        startActivity(intent);
                    }
                }
                return false;
            }
        });
     
     //去掉默认的箭头
     expandablelistView.setGroupIndicator(null);
     
}

/**
  * ExpandableListview (显示树型列表)容器
  * @author user
  *  
  */
public class ExpandableListViewAdapter extends BaseExpandableListAdapter {   
     Activity activity;
public ExpandableListViewAdapter(Activity activity){  
     this.activity = activity;   
     layoutInflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);   
}   
        //child method stub   
        public Object getChild(int ParentPosition, int childPosition) {
            return childrenForums.get(ParentPosition).get(childPosition);   
        }   
  
        public long getChildId(int ParentPosition, int childPosition) {   
            return childPosition;   
        }   
  
        public int getChildrenCount(int ParentPosition) {
            if(childrenForums.size()==0 || childrenForums.get(ParentPosition)==null){
                return 0;
            }
            return childrenForums.get(ParentPosition).size();   
        }   
        
        //填充子item
        public View getChildView(int ParentPosition, int childPosition,   
             boolean isLastChild, View convertView, ViewGroup parent) { 
            ViewHolder holder = null;
            if(convertView==null){
                holder = new ViewHolder();
                convertView=(View)layoutInflater.inflate(R.layout.bbs_category_expandable_child_list_item, null);
                holder.fourmText=(TextView)convertView.findViewById(R.id.bbs_children_list_item);
                convertView.setTag(holder);
            }else{
                holder = (ViewHolder) convertView.getTag();
            }
            if(childrenForums.size()>0 && ParentPosition<childrenForums.size()){
                if(isLastChild){
                    convertView.setBackgroundResource(R.drawable.bbs_categrory_last_children_list);
                }else{
                    convertView.setBackgroundResource(R.drawable.bbs_categrory_children_list);
                }
                if(childPosition<childrenForums.get(ParentPosition).size()){
                    Forum childrenForum = childrenForums.get(ParentPosition).get(childPosition);   
                    holder.fourmText.setText(childrenForum.getPname());
                }
            }
            return convertView;   
        }   
  
        //group method stub   
        public Object getGroup(int ParentPosition) {   
            return parentsForums.get(ParentPosition);   
        }   
  
        public int getGroupCount() {
            if(null==parentsForums || parentsForums.size()==0){
                return 0;
            }
            return parentsForums.size();   
        }   
  
        public long getGroupId(int ParentPosition) {   
            return ParentPosition;   
        }

//填充父item
        public View getGroupView(int ParentPosition, boolean isExpanded,   
                View convertView, ViewGroup parent) {   
            ViewHolder holder = null;
            if(convertView==null){
                holder = new ViewHolder();
                convertView=(View)layoutInflater.inflate(R.layout.bbs_category_expandable_group_list_item, null);
                holder.imageView =(ImageView) convertView.findViewById(R.id.bbs_expandle_list_image);
                holder.fourmText=(TextView)convertView.findViewById(R.id.bbs_category_group_listitem);
                convertView.setTag(holder);
            }else{
                holder = (ViewHolder) convertView.getTag();
            }
            if(parentsForums.size()>0 && ParentPosition<parentsForums.size()){
                Forum parentForum = parentsForums.get(ParentPosition);
                holder.fourmText.setText(parentForum.getPname());
                //设置父item右边的箭头
           if(parentsForums.get(ParentPosition).getChildren()!=null && parentsForums.get   (ParentPosition).getChildren().size()!=0){
                    holder.imageView.setBackgroundResource(R.drawable.bbs_forum_parent_default_image);
                }else{
                    holder.imageView.setBackgroundResource(0);
                }
                //如果展开时 替换右边的箭头
                if(isExpanded && childrenForums.size()>0 && childrenForums.get(ParentPosition)!=null){
                    holder.imageView.setBackgroundResource(R.drawable.bbs_forum_parent_expand_image);
                } 
            }
               return convertView;
        }           
           
        public boolean hasStableIds() {   
            return false;   
        }   
  
        public boolean isChildSelectable(int groupPosition, int childPosition) {   
            return true;   
        }   
    }

class ViewHolder {
          ImageView imageView;
          TextView fourmText;
      }
}

expandableListview的默认箭头箭头怎样移到右边的更多相关文章

  1. ExpandableListView(一)替换系统默认的箭头

    很多朋友可能在android开发中,用过ExpandableListView这个组件,这个组件功能强大,比传统的ListView有好多优势.然而在开发中,我相信有好多人,包括我个人都会遇到下面的一些问 ...

  2. 修改select默认小箭头

    在html中select下拉框默认的小箭头是这样的 有时候我们需要把这种小箭头用更好看的图片代替,就需要改变样式了. html 代码如下: <select class="comm-se ...

  3. -webkit-appearance: none;去处select默认小箭头样式

    Html <select class="sel_house_type"> <option value="0">请选择</optio ...

  4. Android之Toolbar的三个问题:修改左边箭头颜色、怎样修改右边以及子activity中的toolbar添加返回箭头

    1)怎样修改左边这个小箭头的颜色? 2)怎样修改右边这三个点的颜色.怎样把这三个点替换成我自己的图标? 3)怎样让"交易清单"这4个字居中显示? 首先设置Theme为AppComp ...

  5. ExpandableListView的完美实现,JSON数据源,右边自定义图片

    转载请标明出处: http://www.cnblogs.com/dingxiansen/p/8194669.html 本文出自:丁先森-博客园 最近在项目中要使用ExpandableListView来 ...

  6. cxGrid的FilterRow默认自动匹配左边%而不是右边%

    /==============================================================================// 修改cxGrid的FilterRow ...

  7. ubuntu 14.04 将窗体button移到右边

    刚刚安装了Ubuntu 14.04,想改动窗体button的位置.但依照曾经的办法发现不行了,在gconftool-->apps中找不到metacity. 多方查找后找到解决方式,例如以下 Ub ...

  8. ExpandableListView 箭头靠右

    ExpandableListView 默认标示箭头是在左边的,当左边有图片时,不是太好看,想把它放在右边,这么简单的事可我折腾死了,还好给我找到了. 参照了以下链接: expandableListvi ...

  9. DS控件库 Win7链接列表框效果1:右侧箭头

    Win7链接列表框是仿Windos7开始菜单项开发的控件,同样支持右侧箭头,由于使用场合的不同,本控件中右键箭头不作为菜单扩展,而是通过事件触发式响应. 先上图 代码很简单,点击对右侧箭头区域点击的响 ...

随机推荐

  1. 在前后端分离的SpringBoot项目中集成Shiro权限框架

    参考[1].在前后端分离的SpringBoot项目中集成Shiro权限框架 参考[2]. Springboot + Vue + shiro 实现前后端分离.权限控制   以及跨域的问题也有涉及

  2. js 技巧 (十)广告JS代码效果大全 【2】

    2.[鼠标感应]     与前面一个代码不同的是,当鼠标移动到广告图片上是可以感应显示另外设置好的广告大图效果,下面就是实现效果所需代码: function bigshow(){     docume ...

  3. wepy 编译警告去除办法

    如果你用过wepy打包小程序的话,那么你一定碰到了很多坑,(什么也不用说,抱一下吧)下面记录的是本人遇到的一个小坑, 编译的时候出现了黄色警告 如果你出现了上图这样的话,相信你一定也知道什么意思,就是 ...

  4. c++基础_特殊的数字

    #include <iostream> #include <math.h> using namespace std; int main(){ ;i<;i++){ ; )% ...

  5. python视频 神经网络 Tensorflow

    python视频 神经网络 Tensorflow 模块 视频教程 (带源码) 所属网站分类: 资源下载 > python视频教程 作者:smile 链接:http://www.pythonhei ...

  6. C语言学习8

    计算某日是该年的第几天 编写一个计算天数的程序,用户从键盘输入年.月.日,在屏幕中输出此日期是该年的第几天. /******************************************** ...

  7. UVA - 10976 分数拆分

    题意: 给定正整数k(1<=k <= 10000),找出所有正整数 x>= y, 使得1/k = 1/x + 1/y 分析: 因为 x >= y 所以 1/x <= 1/ ...

  8. 17-看图理解数据结构与算法系列(NoSQL存储-LSM树)

    关于LSM树 LSM树,即日志结构合并树(Log-Structured Merge-Tree).其实它并不属于一个具体的数据结构,它更多是一种数据结构的设计思想.大多NoSQL数据库核心思想都是基于L ...

  9. RS232

    RS232的最大的传输速率大约10KBytes/s. 全双工工作方式,异步.数据是8位作为一块来发送的,先发送最低位,最后发送最高位. 在232通信中: Both side of the cable ...

  10. 安装eclipse插件,很慢终于找到了解决的方法

    1 .除非你需要,否则不要选择"联接到所有更新站点" 在安装对话框里有一个小复选框,其标示为"在安装过程中联接到所有更新站点从而找到所需的软件."从表面上看,这 ...