expandableListview的默认箭头箭头怎样移到右边
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的默认箭头箭头怎样移到右边的更多相关文章
- ExpandableListView(一)替换系统默认的箭头
很多朋友可能在android开发中,用过ExpandableListView这个组件,这个组件功能强大,比传统的ListView有好多优势.然而在开发中,我相信有好多人,包括我个人都会遇到下面的一些问 ...
- 修改select默认小箭头
在html中select下拉框默认的小箭头是这样的 有时候我们需要把这种小箭头用更好看的图片代替,就需要改变样式了. html 代码如下: <select class="comm-se ...
- -webkit-appearance: none;去处select默认小箭头样式
Html <select class="sel_house_type"> <option value="0">请选择</optio ...
- Android之Toolbar的三个问题:修改左边箭头颜色、怎样修改右边以及子activity中的toolbar添加返回箭头
1)怎样修改左边这个小箭头的颜色? 2)怎样修改右边这三个点的颜色.怎样把这三个点替换成我自己的图标? 3)怎样让"交易清单"这4个字居中显示? 首先设置Theme为AppComp ...
- ExpandableListView的完美实现,JSON数据源,右边自定义图片
转载请标明出处: http://www.cnblogs.com/dingxiansen/p/8194669.html 本文出自:丁先森-博客园 最近在项目中要使用ExpandableListView来 ...
- cxGrid的FilterRow默认自动匹配左边%而不是右边%
/==============================================================================// 修改cxGrid的FilterRow ...
- ubuntu 14.04 将窗体button移到右边
刚刚安装了Ubuntu 14.04,想改动窗体button的位置.但依照曾经的办法发现不行了,在gconftool-->apps中找不到metacity. 多方查找后找到解决方式,例如以下 Ub ...
- ExpandableListView 箭头靠右
ExpandableListView 默认标示箭头是在左边的,当左边有图片时,不是太好看,想把它放在右边,这么简单的事可我折腾死了,还好给我找到了. 参照了以下链接: expandableListvi ...
- DS控件库 Win7链接列表框效果1:右侧箭头
Win7链接列表框是仿Windos7开始菜单项开发的控件,同样支持右侧箭头,由于使用场合的不同,本控件中右键箭头不作为菜单扩展,而是通过事件触发式响应. 先上图 代码很简单,点击对右侧箭头区域点击的响 ...
随机推荐
- Yii 2.0 query模式语法
项目使用Yii 2.0版本开发,个人一直喜好使用(new \yii\db\Query())模式操作数据,把增.删.查.改这4种情况的写法整理出来,方便查阅和记忆. 增加 - insert use Yi ...
- Bootstrap 12 栅格系统
栅格系统简介 Bootstrap 提供了一套响应式.移动设备优先的流式栅格系统,随着屏幕或视口(viewport)尺寸的增加,系统会自动分为最多 12 列.它包含了易于使用的预定义类,还有强大的mix ...
- linux性能优化cpu-01性能指标
学习性能优化的第一步,一定要了解性能指标. 性能指标是什么? 当我们看到性能指标时一定先想到“高并发”.“响应快”,这个两个指标也对应着性能优化的两个核心指标—— “吞吐率”和“低延迟”. 这两个指标 ...
- Linux思维导图之网络管理
查漏补缺,理解概念,及时总结,欢迎拍砖. IP地址和MAC地址: 1.设计形态不同.IP地址是基于网络拓扑设计出来的,可以人为改动:而MAC地址是制造商烧录好的不能改动,网卡决定了MAC地址,是固定的 ...
- JavaScript小技巧整理篇(非常全)
能够为大家提供这些简短而实用的JavaScript技巧来提高大家编程能力,这对于我来说是件很开心的事.每天仅花上不到2分钟的时间中,你将可 以读遍JavaScript这门可怕的语言所呈现给我们的特性: ...
- 转:Centos7安装zabbix3.4超详细步骤解析
安装前准备: 1.1 安装依赖包: yum -y install wget net-snmp-devel OpenIPMI-devel httpd openssl-devel java lrzsz f ...
- Windows Server 2008 R2 Enterprise 安装.NET Framework 4.0
由于服务器上没有.NET 4.0 部署不了 4.0及以上版本的网站,所以给他安排一下: 复制下好的.NET Framework 4.0到服务器开始安装: 安装完,重新打开IIS,已经 ...
- FPGA学习笔记(六)—— 时序逻辑电路设计
用always@(posedge clk)描述 时序逻辑电路的基础——计数器(在每个时钟的上升沿递增1) 例1.四位计数器(同步使能.异步复位) // Module Name: coun ...
- 关于.NET玩爬虫这些事 【初码干货】
这几天在微信群里又聊到.NET可以救中国但是案例太少不深的问题,我说.NET玩爬虫简直就是宇宙第一,于是大神朱永光说,你为何不来写一篇总结一下? 那么今天就全面的来总结一下,在.NET生态下,如何玩爬 ...
- Android SwipeSelector
Android SwipeSelector Android SwipeSelector是github上一个第三方开源的项目,其项目主页:https://github.com/roughike/S ...