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. Python 绑定方法与非绑定方法

    用到的: import uuid  --------------  uuid是128位的全局唯一标识符, 通常用32位的一个字符串的形式来表现 uuid.uuid1()  -------------  ...

  2. mysql主库与从库配置(并行复制配置)

    主库: [mysqld] server-id = 2233port = 13306basedir = /usr/local/mysqldatadir = /usr/local/mysql/data s ...

  3. 零基础入门学习Python(7)--了不起的分支和循环1

    前言 我们今天的主题,是了不起的分支和循环,为什么不说c语言,Python了不起,而对分支和循环这两个知识点那么崇拜呢? 我们之前的几节课里也接触到了分支和循环,大家思考一下,如果我们的程序没有分支和 ...

  4. 【笔记】搭建OpenWrt编译环境

    参考书目<B智能路由开发指南> 目标:搭建一个OpenWrt编译环境,可以同时在家里和公司使用. [2018-09-13] 刚开始想用自己的电脑共享远程桌面,但不知道什么原因搞不定,所以干 ...

  5. 集训第五周动态规划 C题 编辑距离

    Description Let x and y be two strings over some finite alphabet A. We would like to transform x int ...

  6. UVA 140 Bandwidth (dfs 剪枝 映射)

    题意: 给定一个n个结点的图G和一个结点的排列, 定义结点i的带宽b(i)为i和相邻结点在排列中的最远距离, 所有b(i)的最大值就是这个图的带宽, 给定G, 求让带宽最小的结点排列. 给定的图 n ...

  7. 关于解决ssh的"Write failed: Broken pipe"问题

    操作环境: 服务器:微软云 Linux CentOS 虚拟机 客户端:MAC OSX terminal 问题描述: 登录虚拟机短时间内不操作就会断开连接并报该“Write failed: Broken ...

  8. IDEA-基本设置

    目录: 1.设置内存 2.设置编码格式 3.设置换行符 4.设置新建Class文档说明 5.添加自定义注释 6.设置自己的maven 工欲善其事,必先利其器,设置好基础的设置才能事半功倍!少踩坑!以下 ...

  9. Webdriver概述(selenium对应浏览器版本)

    Webdriver (Selenium2)是一种用于Web应用程序的自动测试工具,它提供了一套友好的API,与Selenium 1(Selenium-RC)相比,Webdriver 的API更容易理解 ...

  10. [luoguP1010] 幂次方 ^(* ̄(oo) ̄)^

    传送门 递归.. 代码 #include <cstdio> int n; int bit[15]; inline void solve(int x) { int i, f = 0; if( ...