Android 仿QQ好友列表分组悬浮PinnedHeaderExpandableListView

转载自:http://blog.csdn.net/h7870181/article/details/40400155






楼主是在平板上测试的,图片稍微有点大,大家看看效果就好


接下来贴源码:

PinnedHeaderExpandableListView.Java 

要注意的是 在 onGroupClick方法中parent.setSelectedGroup(groupPosition)这句代码的作用是点击分组置顶,

我这边不需要这个效果,QQ也没有用到,所以给注释了,大家如果需要可以解开注释

[java]  view plain  copy
 print ? 在CODE上查看代码片 派生到我的代码片
  1. package com.xiaos.view;  
  2.   
  3. import android.content.Context;  
  4. import android.graphics.Canvas;  
  5. import android.util.AttributeSet;  
  6. import android.view.MotionEvent;  
  7. import android.view.View;  
  8. import android.view.ViewGroup;  
  9. import android.widget.AbsListView;  
  10. import android.widget.AbsListView.OnScrollListener;  
  11. import android.widget.ExpandableListAdapter;  
  12. import android.widget.ExpandableListView;  
  13. import android.widget.ExpandableListView.OnGroupClickListener;  
  14.   
  15. public class PinnedHeaderExpandableListView extends ExpandableListView implements OnScrollListener,OnGroupClickListener {  
  16.     public PinnedHeaderExpandableListView(Context context, AttributeSet attrs, int defStyle) {  
  17.         super(context, attrs, defStyle);  
  18.         registerListener();  
  19.     }  
  20.   
  21.     public PinnedHeaderExpandableListView(Context context, AttributeSet attrs) {  
  22.         super(context, attrs);  
  23.         registerListener();  
  24.     }  
  25.   
  26.     public PinnedHeaderExpandableListView(Context context) {  
  27.         super(context);  
  28.         registerListener();  
  29.     }  
  30.   
  31.     /** 
  32.      * Adapter 接口 . 列表必须实现此接口 . 
  33.      */  
  34.     public interface HeaderAdapter {  
  35.         public static final int PINNED_HEADER_GONE = 0;  
  36.         public static final int PINNED_HEADER_VISIBLE = 1;  
  37.         public static final int PINNED_HEADER_PUSHED_UP = 2;  
  38.           
  39.         /** 
  40.          * 获取 Header 的状态 
  41.          * @param groupPosition 
  42.          * @param childPosition 
  43.          * @return PINNED_HEADER_GONE,PINNED_HEADER_VISIBLE,PINNED_HEADER_PUSHED_UP 其中之一 
  44.          */  
  45.         int getHeaderState(int groupPosition, int childPosition);  
  46.   
  47.         /** 
  48.          * 配置 Header, 让 Header 知道显示的内容 
  49.          * @param header 
  50.          * @param groupPosition 
  51.          * @param childPosition 
  52.          * @param alpha 
  53.          */  
  54.         void configureHeader(View header, int groupPosition,int childPosition, int alpha);  
  55.   
  56.         /** 
  57.          * 设置组按下的状态  
  58.          * @param groupPosition 
  59.          * @param status 
  60.          */  
  61.         void setGroupClickStatus(int groupPosition, int status);  
  62.   
  63.         /** 
  64.          * 获取组按下的状态 
  65.          * @param groupPosition 
  66.          * @return 
  67.          */  
  68.         int getGroupClickStatus(int groupPosition);  
  69.   
  70.     }  
  71.   
  72.     private static final int MAX_ALPHA = 255;  
  73.   
  74.     private HeaderAdapter mAdapter;  
  75.   
  76.     /** 
  77.      * 用于在列表头显示的 View,mHeaderViewVisible 为 true 才可见 
  78.      */  
  79.     private View mHeaderView;  
  80.   
  81.     /** 
  82.      * 列表头是否可见 
  83.      */  
  84.     private boolean mHeaderViewVisible;  
  85.   
  86.     private int mHeaderViewWidth;  
  87.   
  88.     private int mHeaderViewHeight;  
  89.   
  90.     public void setHeaderView(View view) {  
  91.         mHeaderView = view;  
  92.         AbsListView.LayoutParams lp = new AbsListView.LayoutParams(  
  93.         ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);  
  94.         view.setLayoutParams(lp);  
  95.   
  96.         if (mHeaderView != null) {  
  97.             setFadingEdgeLength(0);  
  98.         }  
  99.   
  100.         requestLayout();  
  101.     }  
  102.   
  103.     private void registerListener() {  
  104.         setOnScrollListener(this);  
  105.         setOnGroupClickListener(this);  
  106.     }  
  107.   
  108.     /** 
  109.      * 点击 HeaderView 触发的事件 
  110.      */  
  111.     private void headerViewClick() {  
  112.         long packedPosition = getExpandableListPosition(this.getFirstVisiblePosition());  
  113.           
  114.         int groupPosition = ExpandableListView.getPackedPositionGroup(packedPosition);  
  115.           
  116.         if (mAdapter.getGroupClickStatus(groupPosition) == 1) {  
  117.             this.collapseGroup(groupPosition);  
  118.             mAdapter.setGroupClickStatus(groupPosition, 0);  
  119.         }  
  120.         else{  
  121.             this.expandGroup(groupPosition);  
  122.             mAdapter.setGroupClickStatus(groupPosition, 1);  
  123.         }  
  124.           
  125.         this.setSelectedGroup(groupPosition);  
  126.     }  
  127.   
  128.     private float mDownX;  
  129.     private float mDownY;  
  130.   
  131.     /** 
  132.      * 如果 HeaderView 是可见的 , 此函数用于判断是否点击了 HeaderView, 并对做相应的处理 , 
  133.      * 因为 HeaderView 是画上去的 , 所以设置事件监听是无效的 , 只有自行控制 . 
  134.      */  
  135.     @Override  
  136.     public boolean onTouchEvent(MotionEvent ev) {  
  137.         if (mHeaderViewVisible) {  
  138.             switch (ev.getAction()) {  
  139.             case MotionEvent.ACTION_DOWN:  
  140.                 mDownX = ev.getX();  
  141.                 mDownY = ev.getY();  
  142.                 if (mDownX <= mHeaderViewWidth && mDownY <= mHeaderViewHeight) {  
  143.                     return true;  
  144.                 }  
  145.                 break;  
  146.             case MotionEvent.ACTION_UP:  
  147.                 float x = ev.getX();  
  148.                 float y = ev.getY();  
  149.                 float offsetX = Math.abs(x - mDownX);  
  150.                 float offsetY = Math.abs(y - mDownY);  
  151.                 // 如果 HeaderView 是可见的 , 点击在 HeaderView 内 , 那么触发 headerClick()  
  152.                 if (x <= mHeaderViewWidth && y <= mHeaderViewHeight  
  153.                 && offsetX <= mHeaderViewWidth && offsetY <= mHeaderViewHeight) {  
  154.                     if (mHeaderView != null) {  
  155.                         headerViewClick();  
  156.                     }  
  157.   
  158.                     return true;  
  159.                 }  
  160.                 break;  
  161.             default:  
  162.                 break;  
  163.             }  
  164.         }  
  165.   
  166.         return super.onTouchEvent(ev);  
  167.   
  168.     }  
  169.   
  170.     @Override  
  171.     public void setAdapter(ExpandableListAdapter adapter) {  
  172.         super.setAdapter(adapter);  
  173.         mAdapter = (HeaderAdapter) adapter;  
  174.     }  
  175.   
  176.     /** 
  177.      *  
  178.      * 点击了 Group 触发的事件 , 要根据根据当前点击 Group 的状态来 
  179.      */  
  180.     @Override  
  181.     public boolean onGroupClick(ExpandableListView parent,View v,int groupPosition,long id) {  
  182.         if (mAdapter.getGroupClickStatus(groupPosition) == 0) {  
  183.             mAdapter.setGroupClickStatus(groupPosition, 1);  
  184.             parent.expandGroup(groupPosition);  
  185.             //Header自动置顶  
  186.             //parent.setSelectedGroup(groupPosition);  
  187.               
  188.         } else if (mAdapter.getGroupClickStatus(groupPosition) == 1) {  
  189.             mAdapter.setGroupClickStatus(groupPosition, 0);  
  190.             parent.collapseGroup(groupPosition);  
  191.         }  
  192.   
  193.         // 返回 true 才可以弹回第一行 , 不知道为什么  
  194.         return true;  
  195.     }  
  196.   
  197.     @Override  
  198.     protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {  
  199.         super.onMeasure(widthMeasureSpec, heightMeasureSpec);  
  200.         if (mHeaderView != null) {  
  201.             measureChild(mHeaderView, widthMeasureSpec, heightMeasureSpec);  
  202.             mHeaderViewWidth = mHeaderView.getMeasuredWidth();  
  203.             mHeaderViewHeight = mHeaderView.getMeasuredHeight();  
  204.         }  
  205.     }  
  206.   
  207.     private int mOldState = -1;  
  208.   
  209.     @Override  
  210.     protected void onLayout(boolean changed, int left, int top, int right,int bottom) {  
  211.         super.onLayout(changed, left, top, right, bottom);  
  212.         final long flatPostion = getExpandableListPosition(getFirstVisiblePosition());  
  213.         final int groupPos = ExpandableListView.getPackedPositionGroup(flatPostion);  
  214.         final int childPos = ExpandableListView.getPackedPositionChild(flatPostion);  
  215.         int state = mAdapter.getHeaderState(groupPos, childPos);  
  216.         if (mHeaderView != null && mAdapter != null && state != mOldState) {  
  217.             mOldState = state;  
  218.             mHeaderView.layout(00, mHeaderViewWidth, mHeaderViewHeight);  
  219.         }  
  220.   
  221.         configureHeaderView(groupPos, childPos);  
  222.     }  
  223.   
  224.     public void configureHeaderView(int groupPosition, int childPosition) {  
  225.         if (mHeaderView == null || mAdapter == null  
  226.         || ((ExpandableListAdapter) mAdapter).getGroupCount() == 0) {  
  227.             return;  
  228.         }  
  229.   
  230.         int state = mAdapter.getHeaderState(groupPosition, childPosition);  
  231.   
  232.         switch (state) {  
  233.             case HeaderAdapter.PINNED_HEADER_GONE: {  
  234.                 mHeaderViewVisible = false;  
  235.                 break;  
  236.             }  
  237.       
  238.             case HeaderAdapter.PINNED_HEADER_VISIBLE: {  
  239.                 mAdapter.configureHeader(mHeaderView, groupPosition,childPosition, MAX_ALPHA);  
  240.       
  241.                 if (mHeaderView.getTop() != 0){  
  242.                     mHeaderView.layout(00, mHeaderViewWidth, mHeaderViewHeight);  
  243.                 }  
  244.       
  245.                 mHeaderViewVisible = true;  
  246.       
  247.                 break;  
  248.             }  
  249.       
  250.             case HeaderAdapter.PINNED_HEADER_PUSHED_UP: {  
  251.                 View firstView = getChildAt(0);  
  252.                 int bottom = firstView.getBottom();  
  253.       
  254.                 // intitemHeight = firstView.getHeight();  
  255.                 int headerHeight = mHeaderView.getHeight();  
  256.       
  257.                 int y;  
  258.       
  259.                 int alpha;  
  260.       
  261.                 if (bottom < headerHeight) {  
  262.                     y = (bottom - headerHeight);  
  263.                     alpha = MAX_ALPHA * (headerHeight + y) / headerHeight;  
  264.                 } else {  
  265.                     y = 0;  
  266.                     alpha = MAX_ALPHA;  
  267.                 }  
  268.               
  269.                 mAdapter.configureHeader(mHeaderView, groupPosition,childPosition, alpha);  
  270.       
  271.                 if (mHeaderView.getTop() != y) {  
  272.                     mHeaderView.layout(0, y, mHeaderViewWidth, mHeaderViewHeight + y);  
  273.                 }  
  274.       
  275.                 mHeaderViewVisible = true;  
  276.                 break;  
  277.             }  
  278.         }  
  279.     }  
  280.   
  281.     @Override  
  282.     /** 
  283.      * 列表界面更新时调用该方法(如滚动时) 
  284.      */  
  285.     protected void dispatchDraw(Canvas canvas) {  
  286.         super.dispatchDraw(canvas);  
  287.         if (mHeaderViewVisible) {  
  288.             //分组栏是直接绘制到界面中,而不是加入到ViewGroup中  
  289.             drawChild(canvas, mHeaderView, getDrawingTime());  
  290.         }  
  291.     }  
  292.   
  293.     @Override  
  294.     public void onScroll(AbsListView view, int firstVisibleItem,int visibleItemCount, int totalItemCount) {  
  295.         final long flatPos = getExpandableListPosition(firstVisibleItem);  
  296.         int groupPosition = ExpandableListView.getPackedPositionGroup(flatPos);  
  297.         int childPosition = ExpandableListView.getPackedPositionChild(flatPos);  
  298.           
  299.         configureHeaderView(groupPosition, childPosition);  
  300.     }  
  301.   
  302.     @Override  
  303.     public void onScrollStateChanged(AbsListView view, int scrollState) {  
  304.     }  
  305. }  


PinnedHeaderExpandableAdapter.java 适配器 

实现了PinnedHeaderExpandableListView中HeaderAdapter接口


[java]  view plain  copy
 print ?
  1. package com.xiaos.adapter;  
  2.   
  3. import android.content.Context;  
  4. import android.util.SparseIntArray;  
  5. import android.view.LayoutInflater;  
  6. import android.view.View;  
  7. import android.view.ViewGroup;  
  8. import android.widget.BaseExpandableListAdapter;  
  9. import android.widget.ImageView;  
  10. import android.widget.TextView;  
  11.   
  12. import com.xiaos.pinnedheaderexpandable.R;  
  13. import com.xiaos.view.PinnedHeaderExpandableListView;  
  14. import com.xiaos.view.PinnedHeaderExpandableListView.HeaderAdapter;  
  15.   
  16. public class PinnedHeaderExpandableAdapter extends BaseExpandableListAdapter implements HeaderAdapter{  
  17. private String[][] childrenData;  
  18. private String[] groupData;  
  19. private Context context;  
  20. private PinnedHeaderExpandableListView listView;  
  21. private LayoutInflater inflater;  
  22.   
  23. public PinnedHeaderExpandableAdapter(String[][] childrenData,String[] groupData  
  24. ,Context context,PinnedHeaderExpandableListView listView){  
  25. this.groupData = groupData;   
  26. this.childrenData = childrenData;  
  27. this.context = context;  
  28. this.listView = listView;  
  29. inflater = LayoutInflater.from(this.context);  
  30. }  
  31.   
  32. @Override  
  33. public Object getChild(int groupPosition, int childPosition) {  
  34. return childrenData[groupPosition][childPosition];  
  35. }  
  36.   
  37. @Override  
  38. public long getChildId(int groupPosition, int childPosition) {  
  39. return 0;  
  40. }  
  41.   
  42. @Override  
  43. public View getChildView(int groupPosition, int childPosition,  
  44. boolean isLastChild, View convertView, ViewGroup parent) {  
  45. View view = null;   
  46. if (convertView != null) {   
  47. view = convertView;   
  48. else {   
  49. view = createChildrenView();   
  50. }   
  51. TextView text = (TextView)view.findViewById(R.id.childto);  
  52. text.setText(childrenData[groupPosition][childPosition]);   
  53. return view;   
  54. }  
  55.   
  56. @Override  
  57. public int getChildrenCount(int groupPosition) {  
  58. return childrenData[groupPosition].length;  
  59. }  
  60.   
  61. @Override  
  62. public Object getGroup(int groupPosition) {  
  63. return groupData[groupPosition];  
  64. }  
  65.   
  66. @Override  
  67. public int getGroupCount() {  
  68. return groupData.length;  
  69. }  
  70.   
  71. @Override  
  72. public long getGroupId(int groupPosition) {  
  73. return 0;  
  74. }  
  75.   
  76. @Override  
  77. public View getGroupView(int groupPosition, boolean isExpanded,  
  78. View convertView, ViewGroup parent) {  
  79. View view = null;   
  80. if (convertView != null) {   
  81. view = convertView;   
  82. else {   
  83. view = createGroupView();   
  84. }   
  85.   
  86. ImageView iv = (ImageView)view.findViewById(R.id.groupIcon);  
  87.   
  88. if (isExpanded) {  
  89. iv.setImageResource(R.drawable.btn_browser2);  
  90. }  
  91. else{  
  92. iv.setImageResource(R.drawable.btn_browser);  
  93. }  
  94.   
  95. TextView text = (TextView)view.findViewById(R.id.groupto);  
  96. text.setText(groupData[groupPosition]);   
  97. return view;   
  98. }  
  99.   
  100. @Override  
  101. public boolean hasStableIds() {  
  102. return true;  
  103. }  
  104.   
  105. @Override  
  106. public boolean isChildSelectable(int groupPosition, int childPosition) {  
  107. return true;  
  108. }  
  109.   
  110. private View createChildrenView() {  
  111. return inflater.inflate(R.layout.child, null);  
  112. }  
  113.   
  114. private View createGroupView() {  
  115. return inflater.inflate(R.layout.group, null);  
  116. }  
  117.   
  118. @Override  
  119. public int getHeaderState(int groupPosition, int childPosition) {  
  120. final int childCount = getChildrenCount(groupPosition);  
  121. if (childPosition == childCount - 1) {  
  122. return PINNED_HEADER_PUSHED_UP;  
  123. else if (childPosition == -1  
  124. && !listView.isGroupExpanded(groupPosition)) {  
  125. return PINNED_HEADER_GONE;  
  126. else {  
  127. return PINNED_HEADER_VISIBLE;  
  128. }  
  129. }  
  130.   
  131. @Override  
  132. public void configureHeader(View header, int groupPosition,  
  133. int childPosition, int alpha) {  
  134. String groupData = this.groupData[groupPosition];  
  135. ((TextView) header.findViewById(R.id.groupto)).setText(groupData);  
  136.   
  137. }  
  138.   
  139. private SparseIntArray groupStatusMap = new SparseIntArray();   
  140.   
  141. @Override  
  142. public void setGroupClickStatus(int groupPosition, int status) {  
  143. groupStatusMap.put(groupPosition, status);  
  144. }  
  145.   
  146. @Override  
  147. public int getGroupClickStatus(int groupPosition) {  
  148. if (groupStatusMap.keyAt(groupPosition)>=0) {  
  149. return groupStatusMap.get(groupPosition);  
  150. else {  
  151. return 0;  
  152. }  
  153. }  
  154. }  


MainActivity.java主Activity

[java]  view plain  copy
 print ? 在CODE上查看代码片 派生到我的代码片
  1. package com.xiaos.pinnedheaderexpandable;  
  2.   
  3. import android.app.Activity;  
  4. import android.os.Bundle;  
  5. import android.view.View;  
  6. import android.widget.ExpandableListView;  
  7. import android.widget.ExpandableListView.OnGroupClickListener;  
  8.   
  9. import com.xiaos.adapter.PinnedHeaderExpandableAdapter;  
  10. import com.xiaos.view.PinnedHeaderExpandableListView;  
  11.   
  12. public class MainActivity extends Activity{  
  13.     private PinnedHeaderExpandableListView explistview;  
  14.     private String[][] childrenData = new String[10][10];  
  15.     private String[] groupData = new String[10];  
  16.     private int expandFlag = -1;//控制列表的展开    
  17.     private PinnedHeaderExpandableAdapter adapter;  
  18.       
  19.       
  20.     @Override  
  21.     protected void onCreate(Bundle savedInstanceState) {  
  22.         super.onCreate(savedInstanceState);  
  23.         setContentView(R.layout.layout_main);  
  24.         initView();  
  25.         initData();  
  26.     }  
  27.       
  28.     /** 
  29.      * 初始化VIEW 
  30.      */  
  31.     private void initView() {  
  32.         explistview = (PinnedHeaderExpandableListView)findViewById(R.id.explistview);  
  33.     }  
  34.   
  35.     /** 
  36.      * 初始化数据 
  37.      */  
  38.     private void initData() {  
  39.         for(int i=0;i<10;i++){  
  40.             groupData[i] = "分组"+i;  
  41.         }  
  42.           
  43.         for(int i=0;i<10;i++){  
  44.             for(int j=0;j<10;j++){  
  45.                 childrenData[i][j] = "好友"+i+"-"+j;  
  46.             }  
  47.         }  
  48.         //设置悬浮头部VIEW  
  49.         explistview.setHeaderView(getLayoutInflater().inflate(R.layout.group_head,  
  50.                 explistview, false));  
  51.         adapter = new PinnedHeaderExpandableAdapter(childrenData, groupData, getApplicationContext(),explistview);  
  52.         explistview.setAdapter(adapter);  
  53.           
  54.         //设置单个分组展开  
  55.         //explistview.setOnGroupClickListener(new GroupClickListener());  
  56.     }  
  57.       
  58.     class GroupClickListener implements OnGroupClickListener{  
  59.         @Override  
  60.         public boolean onGroupClick(ExpandableListView parent, View v,  
  61.                 int groupPosition, long id) {  
  62.             if (expandFlag == -1) {  
  63.                 // 展开被选的group  
  64.                 explistview.expandGroup(groupPosition);  
  65.                 // 设置被选中的group置于顶端  
  66.                 explistview.setSelectedGroup(groupPosition);  
  67.                 expandFlag = groupPosition;  
  68.             } else if (expandFlag == groupPosition) {  
  69.                 explistview.collapseGroup(expandFlag);  
  70.                 expandFlag = -1;  
  71.             } else {  
  72.                 explistview.collapseGroup(expandFlag);  
  73.                 // 展开被选的group  
  74.                 explistview.expandGroup(groupPosition);  
  75.                 // 设置被选中的group置于顶端  
  76.                 explistview.setSelectedGroup(groupPosition);  
  77.                 expandFlag = groupPosition;  
  78.             }  
  79.             return true;  
  80.         }  
  81.     }  
  82. }  

布局文件

child.xml

[html]  view plain  copy
 print ? 在CODE上查看代码片 派生到我的代码片
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     android:layout_width="match_parent"  
  4.     android:layout_height="40dip"  
  5.     android:background="#FFFFFF" >  
  6.   
  7.     <ImageView  
  8.         android:id="@+id/groupIcon"  
  9.         android:layout_width="40dp"  
  10.         android:layout_height="40dp"  
  11.         android:paddingLeft="10dp"  
  12.         android:src="@null" />  
  13.   
  14.     <TextView  
  15.         android:id="@+id/childto"  
  16.         android:layout_width="match_parent"  
  17.         android:layout_height="match_parent"  
  18.         android:paddingLeft="10dp"  
  19.         android:paddingTop="10dip"  
  20.         android:textColor="#000000"  
  21.         android:textSize="16sp" />  
  22.   
  23. </LinearLayout>  

group_head.xml

[html]  view plain  copy
 print ? 在CODE上查看代码片 派生到我的代码片
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     android:layout_width="match_parent"  
  4.     android:layout_height="wrap_content"  
  5.     android:orientation="horizontal"   
  6.     android:background="#B8E6FA"  
  7.     android:gravity="center_vertical">  
  8.     <ImageView   
  9.         android:id="@+id/groupIcon"  
  10.         android:layout_width="50dp"  
  11.         android:layout_height="50dp"  
  12.         android:contentDescription="@null"  
  13.         android:layout_marginLeft="10dp"  
  14.         android:src="@drawable/btn_browser2"/>  
  15.     <TextView  
  16.         android:id="@+id/groupto"  
  17.         android:layout_width="match_parent"  
  18.         android:layout_height="50dp"  
  19.         android:textColor="#000000"  
  20.         android:textSize="18sp"   
  21.         android:gravity="center_vertical|left"/>  
  22.   
  23. </LinearLayout>  

group.xml

[html]  view plain  copy
 print ? 在CODE上查看代码片 派生到我的代码片
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     android:layout_width="match_parent"  
  4.     android:layout_height="wrap_content"  
  5.     android:orientation="horizontal"   
  6.     android:background="#B8E6FA"  
  7.     android:gravity="center_vertical">  
  8.     <ImageView   
  9.         android:id="@+id/groupIcon"  
  10.         android:layout_width="50dp"  
  11.         android:layout_height="50dp"  
  12.         android:contentDescription="@null"  
  13.         android:layout_marginLeft="10dp"  
  14.         android:src="@drawable/btn_browser"/>  
  15.     <TextView  
  16.         android:id="@+id/groupto"  
  17.         android:layout_width="match_parent"  
  18.         android:layout_height="50dp"  
  19.         android:textColor="#000000"  
  20.         android:textSize="18sp"   
  21.         android:gravity="center_vertical|left"/>  
  22. </LinearLayout>  

layout_main.xml

[html]  view plain  copy
 print ? 在CODE上查看代码片 派生到我的代码片
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     android:layout_width="match_parent"  
  4.     android:layout_height="match_parent"  
  5.     android:background="#F0F0F0"  
  6.     android:orientation="vertical" >  
  7.   
  8.     <com.xiaos.view.PinnedHeaderExpandableListView  
  9.         android:id="@+id/explistview"  
  10.         android:layout_width="match_parent"  
  11.         android:layout_height="match_parent"  
  12.         android:layout_marginLeft="0.0dip"  
  13.         android:cacheColorHint="#00000000"  
  14.         android:choiceMode="singleChoice"  
  15.         android:drawSelectorOnTop="false"  
  16.         android:fastScrollEnabled="false"  
  17.         android:footerDividersEnabled="true"  
  18.         android:groupIndicator="@null"  
  19.         android:scrollbars="vertical"  
  20.         android:scrollingCache="true" />  
  21.   
  22. </LinearLayout>  

AndroidManifest.xml

[html]  view plain  copy
 print ? 在CODE上查看代码片 派生到我的代码片
  1. <manifest xmlns:android="http://schemas.android.com/apk/res/android"  
  2.     package="com.xiaos.pinnedheaderexpandable"  
  3.     android:versionCode="1"  
  4.     android:versionName="1.0" >  
  5.   
  6.     <uses-sdk  
  7.         android:minSdkVersion="8"  
  8.         android:targetSdkVersion="19" />  
  9.   
  10.     <application  
  11.         android:allowBackup="true"  
  12.         android:icon="@drawable/ic_launcher"  
  13.         android:label="@string/app_name"  
  14.         android:theme="@style/AppTheme" >  
  15.         <activity   
  16.             android:name=".MainActivity"  
  17.             android:icon="@drawable/ic_launcher">  
  18.             <intent-filter>  
  19.                 <action android:name="android.intent.action.MAIN"/>  
  20.                 <category android:name="android.intent.category.LAUNCHER"/>  
  21.             </intent-filter>  
  22.         </activity>  
  23.     </application>  
  24.   
  25. </manifest>  

两张图片:

     



下载地址: http://download.csdn.net/detail/h7870181/8073677



转载自:http://blog.csdn.net/h7870181/article/details/40400155



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值