移動開發----帶頭部(headView)和底部(footView)的RecycleView

下載地址:點擊這裏下載
Tag:

項目介紹:

  .idea 更新gif和圖片說明 Sep 26, 2016
  app 修正【刷新完成】至【回滾隱藏】這個過程中用戶狂拽,快速滑動有可能出現的狀態錯誤 Oct 9, 2016
  gradle/wrapper 提交代碼 Jul 3, 2016
  hfrecyleviewlib HFLineHerComDecoration 繪製方式 drawLine() 更新爲 drawRect() Oct 31, 2016
  pics 更新gif和圖片說明 Sep 26, 2016
  .gitignore 提交代碼 Jul 3, 2016
  README.md 更新gif和圖片說明 Sep 26, 2016
  build.gradle 提交代碼 Jul 3, 2016
  gradle.properties 提交代碼 Jul 3, 2016
  gradlew 提交代碼 Jul 3, 2016
  gradlew.bat 提交代碼 Jul 3, 2016
  hfrecycleview.gif Add files via upload Jul 3, 2016
  settings.gradle 提交代碼 Jul 3, 2016

帶頭部(headView)和底部(footView)的RecycleView。分裝了recycleview.adater裏面的初始化和構建。更加便捷的使用的recycleview



效果圖



554



554



xml文件



[Java] 查看源文件 複製代碼
1
2
3
4
5
6
<!--?xml version=\"1.0\" encoding=\"utf-8\"?-->
<com.igeek.hfrecyleviewlib.nestedrefreshlayout android:id="\"@+id/refreshLayout\"" app:pullviewheight="\"60dp\"" app:pullmaxheight="\"100dp\"" android:layout_width="\"match_parent\"" android:layout_height="\"match_parent\"" android:background="\"@android:color/white\"">
 
        <android.support.v7.widget.recyclerview android:id="\"@+id/recycle\"" android:layout_width="\"match_parent\"" android:layout_height="\"match_parent\"">
 
</android.support.v7.widget.recyclerview></com.igeek.hfrecyleviewlib.nestedrefreshlayout>


部分代碼



[Java] 查看源文件 複製代碼
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
class HeadFootActivity extends Activity implements
    BasicRecyViewHolder.OnItemClickListener,
    BasicRecyViewHolder.OnItemLongClickListener,
    BasicRecyViewHolder.OnHeadViewClickListener,
    BasicRecyViewHolder.OnFootViewClickListener {
 
    RecyclerView recyclerView;
    NestedRefreshLayout refreshLayout;
    TestSingleFHFSingleTypeRecyAdapter adapter;
 
    View loadingView;
    View nodataView;
    View topView;
 
 
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        refreshLayout= (NestedRefreshLayout) findViewById(R.id.refreshLayout);
        recyclerView = (RecyclerView) findViewById(R.id.recycle);
        loadingView = getLayoutInflater().inflate(R.layout.layout_listbottom_loadingview, null);
        nodataView = getLayoutInflater().inflate(R.layout.layout_list_nodata, null);
        topView = getLayoutInflater().inflate(R.layout.layout_topview, null);
        if (adapter == null) {
            adapter = new TestSingleFHFSingleTypeRecyAdapter(R.layout.layout_recy_item);
            //添加頭部
            adapter.setHeadView(topView);
            //添加底部
            adapter.setFootView(loadingView);
            //添加item的點擊事件
            adapter.setItemClickListener(this);
            //添加item的長按事件
            adapter.setItemLongClickListener(this);
            //添加頭部的點擊事件
            adapter.setHeadClickListener(this);
            //添加底部的點擊事件
            adapter.setFootClickListener(this);
            //處理item當中子視圖的點擊事件
            adapter.addSubViewListener(R.id.item_btn, new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    Toast.makeText(HeadFootActivity.this,\" 你點擊了第 \"+view.getTag().toString()+\" 個button\",Toast.LENGTH_SHORT).show();
                }
            });
            //處理頭部當中子視圖的點擊事件
            adapter.addHeadSubViewListener(R.id.topview_text, headlistener);
            //處理底部當中子視圖的點擊事件
            adapter.addFootSubViewListener(R.id.nodataview_text, footlistener);
        }
        recyclerView.setAdapter(adapter);
        //添加滾動事件的監聽的處理刷新和加載更多
        recyclerView.addOnScrollListener(srcollListener);
        recyclerView.setLayoutManager(new LinearLayoutManager(this));
        adapter.refreshDatas(buildListByPosition(0));
        refreshLayout.setOnRefreshListener(new NestedRefreshLayout.OnRefreshListener() {
             @Override
             public void onRefresh() {
                //1:send network request data
                //2:refreshLayout.refreshFinish();
             }
        });
    }
}
 
 
@Override
public void OnItemClick(View v, int adapterPosition) {
    //adapterPosition 的位置不一定是數據集當中的位置 獲取真實的位置通過  adapter.getPositon(adapterPosition) 獲得
    Toast.makeText(this, \"你點擊了第 \"+adapter.getPositon(adapterPosition)+\" 個數據item\", Toast.LENGTH_SHORT).show();
}
 
@Override
public void OnItemLongClick(View v, int adapterPosition) {
    //adapterPosition 的位置不一定是數據集當中的位置 獲取真實的位置通過  adapter.getPositon(adapterPosition) 獲得
    Toast.makeText(this, \"你長按了第 \"+adapter.getPositon(adapterPosition)+\" 個數據item\", Toast.LENGTH_SHORT).show();
}
 
@Override
public void onReCycleFootClick(View view, View clickView) {
    Toast.makeText(this, \"你點擊了底部 footView\", Toast.LENGTH_SHORT).show();
}
 
@Override
public void onRecycleHeadClick(View view, View clickView) {
    Toast.makeText(this, \"你點擊了頂部 headView\", Toast.LENGTH_SHORT).show();
}
發佈了55 篇原創文章 · 獲贊 36 · 訪問量 6萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章