网上开源项目:​​https://github.com/beworker/pinned-section-listview​​,该项目用的是ArrayAdapter()..不太适合我,稍作修改,仿的微信界面

PinnedSectionListView修改了一行代码,不然会报错,代码如下

void createPinnedShadow(int position) {}》》


1. if (layoutParams == null) {  
2. //layoutParams = (LayoutParams) generateDefaultLayoutParams();
3. new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
4. pinnedView.setLayoutParams(layoutParams);
5. }



效果图:


Android PinnedSectionListView 收缩_android


Android PinnedSectionListView 收缩_ide_02


Android PinnedSectionListView 收缩_ide_03

具体代码AdapterListView:



1. package pinneactivity.example.ui;  
2.
3. import java.util.ArrayList;
4.
5. import pinneactivity.example.ui.PinnedSectionListView.PinnedSectionListAdapter;
6. import android.content.Context;
7. import android.view.LayoutInflater;
8. import android.view.View;
9. import android.view.ViewGroup;
10. import android.widget.BaseAdapter;
11. import android.widget.ImageView;
12. import android.widget.TextView;
13. /*
14. *
15. * This is company of adapter
16. *
17. * @author YangWenlong
18. */
19. public class AdapterListView extends BaseAdapter implements PinnedSectionListAdapter{
20. private ArrayList<Bean> list;
21. private Context context;
22. public ArrayList<Bean> getList() {
23. return list;
24. }
25. public void setList(ArrayList<Bean> list) {
26. if(list!=null){
27. this.list = list;
28. else{
29. new ArrayList<Bean>();
30. }
31. }
32. public AdapterListView(Context context,ArrayList<Bean> list){
33. this.setList(list);
34. this.context=context;
35. }
36. @Override
37. public int getCount() {
38. // TODO Auto-generated method stub
39. return list.size();
40. }
41.
42. @Override
43. public Bean getItem(int position) {
44. // TODO Auto-generated method stub
45. return list.get(position);
46. }
47.
48. @Override
49. public long getItemId(int position) {
50. // TODO Auto-generated method stub
51. return position;
52. }
53.
54. @Override
55. public View getView(int position, View converView, ViewGroup viewGrop) {
56. // TODO Auto-generated method stub
57. null;
58. if(converView==null){
59. new ViewHolder();
60. null);
61. vh.company_item=(TextView)converView.findViewById(R.id.title);
62. vh.image=(ImageView)converView.findViewById(R.id.imageView1);
63. converView.setTag(vh);
64. else{
65. vh=(ViewHolder) converView.getTag();
66. }
67. Bean bean=getItem(position);
68. vh.company_item.setText(bean.text);
69. if (bean.type == Bean.SECTION) {
70. vh.company_item.setBackgroundResource(R.drawable.bao_headview_bg);
71. vh.image.setVisibility(View.GONE);
72.
73. else{
74. vh.company_item.setBackgroundResource(R.drawable.details_layout_bg);
75. vh.image.setVisibility(View.VISIBLE);
76. }
77. return converView;
78. }
79. @Override
80. public boolean isItemViewTypePinned(int viewType) {
81. // TODO Auto-generated method stub
82. return viewType == Bean.SECTION;//0是标题,1是内容
83. }
84.
85. @Override
86. public int getViewTypeCount() {
87. return 2;//2种view的类型 baseAdapter中得方法
88. }
89. @Override
90. public int getItemViewType(int position) {
91. return ((Bean)getItem(position)).type;
92. }
93. public void refresh(ArrayList<Bean> arr){
94. setList(arr);
95. notifyDataSetChanged();
96. }
97.
98. }


HeadView:



1. package pinneactivity.example.ui;  
2.
3. import android.app.Activity;
4. import android.view.View;
5. import android.view.View.OnClickListener;
6. import android.widget.LinearLayout;
7. import android.widget.Toast;
8.
9. /*
10. * Fail view
11. *
12. * @author YangWenlong
13. */
14. public class HeadView implements OnClickListener{
15. private View view = null;
16. private Activity activity;
17. private LinearLayout newFriends;
18. private LinearLayout grop;
19. private LinearLayout tag;
20. private LinearLayout publicNumber;
21. private static HeadView headView = null;
22.
23. public static HeadView getInstance(Activity activity) {
24. new HeadView(activity);
25. return headView;
26. }
27.
28. public HeadView(Activity activity) {
29. null);
30. this.activity=activity;
31. }
32.
33. public HeadView initialization(){
34. newFriends=(LinearLayout)view.findViewById(R.id.layout_new);
35. grop=(LinearLayout)view.findViewById(R.id.layout_group);
36. tag=(LinearLayout)view.findViewById(R.id.layout_tag);
37. publicNumber=(LinearLayout)view.findViewById(R.id.layout_public);
38.
39. this);
40. this);
41. this);
42. this);
43.
44.
45. return headView;
46. }
47.
48. public View getView(){
49. return view;
50. }
51.
52. @Override
53. public void onClick(View v) {
54. // TODO Auto-generated method stub
55. if(v==newFriends){
56. "新朋友", Toast.LENGTH_SHORT).show();
57. else if(v==grop){
58. "群聊", Toast.LENGTH_SHORT).show();
59. else if(v==tag){
60. "标签", Toast.LENGTH_SHORT).show();
61. else if(v==publicNumber){
62. "公众号", Toast.LENGTH_SHORT).show();
63. }
64. }
65. }