這篇文章主要介紹Spring怎么實(shí)現(xiàn)上拉刷新和下拉加載效果,文中介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們一定要看完!
目前成都創(chuàng)新互聯(lián)已為1000+的企業(yè)提供了網(wǎng)站建設(shè)、域名、虛擬空間、網(wǎng)站托管、企業(yè)網(wǎng)站設(shè)計(jì)、楊浦網(wǎng)站維護(hù)等服務(wù),公司將堅(jiān)持客戶導(dǎo)向、應(yīng)用為本的策略,正道將秉承"和諧、參與、激情"的文化,與客戶和合作伙伴齊心協(xié)力一起成長,共同發(fā)展。
導(dǎo)依賴:
compile 'com.android.support:recyclerview-v7:25.3.1' compile 'com.liaoinstan.springview:library:1.3.0' compile files('libs/glide-3.7.0.jar')
activity_main布局
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" tools:context="muhanxi.recycleview.MainActivity"> <com.liaoinstan.springview.widget.SpringView android:layout_width="match_parent" android:id="@+id/springview" android:layout_height="match_parent"> <android.support.v7.widget.RecyclerView android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/recyclerview"/> </com.liaoinstan.springview.widget.SpringView> </LinearLayout>
MainActivity 主類
public class MainActivity extends Activity { private RecyclerView recyclerView; private List<String> list = new ArrayList<>(); private SpringView springView; private LinearLayoutManager linearLayoutManager; @RequiresApi(api = Build.VERSION_CODES.GINGERBREAD) @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); recyclerView = (RecyclerView) findViewById(R.id.recyclerview); list.add("http://f10.baidu.com/it/u=2881303562,336932824&fm=72"); list.add("http://f11.baidu.com/it/u=681755471,2018070071&fm=72"); list.add("http://f10.baidu.com/it/u=960650584,863938083&fm=72"); list.add("http://img0.imgtn.bdimg.com/it/u=783060973,4278100629&fm=27&gp=0.jpg"); list.add("http://img1.imgtn.bdimg.com/it/u=3743124979,3234956668&fm=27&gp=0.jpg"); list.add("http://img4.imgtn.bdimg.com/it/u=3468613159,957707785&fm=27&gp=0.jpg"); list.add("http://img3.imgtn.bdimg.com/it/u=2971205354,485034289&fm=27&gp=0.jpg"); list.add("http://f10.baidu.com/it/u=2881303562,336932824&fm=72"); list.add("http://f11.baidu.com/it/u=681755471,2018070071&fm=72"); list.add("http://f10.baidu.com/it/u=960650584,863938083&fm=72"); list.add("http://img0.imgtn.bdimg.com/it/u=783060973,4278100629&fm=27&gp=0.jpg"); list.add("http://img1.imgtn.bdimg.com/it/u=3743124979,3234956668&fm=27&gp=0.jpg"); list.add("http://img4.imgtn.bdimg.com/it/u=3468613159,957707785&fm=27&gp=0.jpg"); list.add("http://img3.imgtn.bdimg.com/it/u=2971205354,485034289&fm=27&gp=0.jpg"); // 設(shè)置布局管理器 // new GridLayoutManager() 九宮格布局管理器 // new LinearLayoutManager() listview 布局管理器 // // new StaggeredGridLayoutManager() 瀑布流 布局管理器 // recyclerView.setLayoutManager(new GridLayoutManager(this,5)); // recyclerView.setLayoutManager(new StaggeredGridLayoutManager(3, LinearLayout.VERTICAL)); // RecyclerViewAdapter adapter = new RecyclerViewAdapter(this,list) ; MultiAdapter adapter = new MultiAdapter(this,list) ; linearLayoutManager = new LinearLayoutManager(this,LinearLayoutManager.VERTICAL,false); recyclerView.setLayoutManager(linearLayoutManager); recyclerView.setAdapter(adapter); // // adapter.setIListener(new RecyclerViewAdapter.Listener() { // @Override // public void onClick(View view, int position) { // Toast.makeText(MainActivity.this, ""+position, Toast.LENGTH_SHORT).show(); // } // // @Override // public void longClick(View view, int position) { // // } // }); recyclerView.setOnScrollListener(new RecyclerView.OnScrollListener() { @Override public void onScrollStateChanged(RecyclerView recyclerView, int newState) { super.onScrollStateChanged(recyclerView, newState); // linearLayoutManager.findFirstVisibleItemPosition() } @Override public void onScrolled(RecyclerView recyclerView, int dx, int dy) { super.onScrolled(recyclerView, dx, dy); } }); // recyclerView.setOnI // recyclerView.addItemDecoration(new HorizontalDividerItemDecoration.Builder(this) // .color(Color.RED).build()); springView = (SpringView) findViewById(R.id.springview); springView.setHeader(new DefaultHeader(this)); springView.setFooter(new DefaultFooter(this)); springView.setListener(new SpringView.OnFreshListener() { @Override public void onRefresh() { //下啦 springView.onFinishFreshAndLoad(); } @Override public void onLoadmore() { // 上啦 springView.onFinishFreshAndLoad(); } }); // adapter.notifyDataSetChanged(); } }
下拉布局
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center" android:orientation="vertical"> <ImageView android:src="@mipmap/ic_launcher" android:scaleType="centerCrop" android:id="@+id/item_simageview" android:layout_width="match_parent" android:layout_height="100dp" /> </LinearLayout>
刷新布局
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center" android:orientation="vertical"> <ImageView android:src="@mipmap/ic_launcher" android:id="@+id/item_simageview" android:layout_width="match_parent" android:layout_height="100dp" /> <TextView android:background="@color/colorPrimary" android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/item_stextview"/> </LinearLayout>
MultiAdapter 適配器
public class MultiAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { private Context context; private List<String> list; public MultiAdapter(Context context, List<String> list) { this.context = context; this.list = list; } @Override public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { if (viewType == 0) { View view = LayoutInflater.from(context).inflate(R.layout.layout_fitem,parent, false); return new FViewHolder(view); } else { View view = LayoutInflater.from(context).inflate(R.layout.layout_sitem, parent, false); return new SViewHolder(view); } } @Override public int getItemViewType(int position) { return position % 2 ; } @Override public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { if(holder instanceof FViewHolder){ FViewHolder fViewHolder = (FViewHolder)holder ; fViewHolder.itemStextview.setText(position+""); Glide.with(context).load(list.get(position)).into(fViewHolder.itemSimageview); // ImageLoader.getInstance().displayImage(list.get(position),fViewHolder.itemSimageview); } else { SViewHolder sViewHolder = (SViewHolder)holder ; Glide.with(context).load(list.get(position)).into(sViewHolder.itemSimageview); // ImageLoader.getInstance().displayImage(list.get(position),sViewHolder.itemSimageview); } } @Override public int getItemCount() { return list.size(); } static class FViewHolder extends RecyclerView.ViewHolder{ @BindView(R.id.item_simageview) ImageView itemSimageview; @BindView(R.id.item_stextview) TextView itemStextview; FViewHolder(View view) { super(view); ButterKnife.bind(this, view); } } class SViewHolder extends RecyclerView.ViewHolder{ @BindView(R.id.item_simageview) ImageView itemSimageview; SViewHolder(View view) { super(view); ButterKnife.bind(this, view); } } }
以上是“Spring怎么實(shí)現(xiàn)上拉刷新和下拉加載效果”這篇文章的所有內(nèi)容,感謝各位的閱讀!希望分享的內(nèi)容對(duì)大家有幫助,更多相關(guān)知識(shí),歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道!
網(wǎng)站名稱:Spring怎么實(shí)現(xiàn)上拉刷新和下拉加載效果
分享網(wǎng)址:http://jinyejixie.com/article46/jjpghg.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供定制網(wǎng)站、外貿(mào)網(wǎng)站建設(shè)、營銷型網(wǎng)站建設(shè)、網(wǎng)站設(shè)計(jì)公司、軟件開發(fā)、
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)