android动态刷新主页,Android手把手教大家制作APP首页(下拉刷新、自动加载)

本文将分享如何在Android中实现一个具备下拉刷新和自动加载功能的首页,包括使用LRecyclerView作为主框架,集成convenientbanner实现轮播图,用glide处理图片,以及通过okhttp进行网络请求。详细介绍了关键代码实现,并展示了实际效果。
摘要由CSDN通过智能技术生成

一、概述

作为一名三年Android开发经验的程序员,今天和大家一起实战一款APP的首页功能,这个首页在我们平时接触中还是很常见的,虽然页面简单,但是里面涉及的功能点还是挺多的。代码如有不足的还望各路同仁指点一二。

页面中使用的开发库:

整个首页架构使用的是LRecyclerView,包含下拉刷新和自动加载功能

compile 'com.github.jdsjlzx:LRecyclerView:1.3.3'

无限循环轮播图使用的是convenientbanner,效果还是很顺畅的,还可以根据自己的需要修改过渡动画

compile 'com.bigkoo:convenientbanner:2.0.5'

图片加载使用的是glide图片库,里面的方法是自己封装的

网络请求依赖是okhttp,使用的开源库okgo

compile 'com.lzy.net:okgo:2.1.4'

其他的还是九宫格图

compile 'com.lzy.widget:ninegridview:0.2.0'

自动注解butterknife库等等

二、实现效果图

1.首页展示轮播图

f284b5df22ed0a2065d28ea0ca55839a.gif

2.下拉刷新

d21cadf76acbb095fe342fab41ba24e2.gif

3.自动加载

ce1c44cdf2abeab932cbe058d3de41a2.gif

4.cardview水波纹动画

71491ec050819e73b288e6e8c3807150.gif

三、核心代码

LRecyclerView作为主框架,轮播图以及分类网格列表作为header放在index_header.xml布局文件下。

IndexFragment.java

package com.czhappy.commonindexdemo.fragment;

import android.os.Bundle;

import android.support.v4.app.Fragment;

import android.support.v4.view.ViewPager;

import android.support.v7.widget.LinearLayoutManager;

import android.view.LayoutInflater;

import android.view.View;

import android.view.ViewGroup;

import android.widget.AdapterView;

import android.widget.ImageView;

import android.widget.LinearLayout;

import android.widget.TextView;

import com.bigkoo.convenientbanner.ConvenientBanner;

import com.bigkoo.convenientbanner.holder.CBViewHolderCreator;

import com.czhappy.commonindexdemo.KuaiZhiApplication;

import com.czhappy.commonindexdemo.R;

import com.czhappy.commonindexdemo.adapter.CampaignListAdapter;

import com.czhappy.commonindexdemo.adapter.ClassflyListAdapter;

import com.czhappy.commonindexdemo.jsonparse.JSONObject;

import com.czhappy.commonindexdemo.jsonparse.ReflectUtil;

import com.czhappy.commonindexdemo.model.CampaignList;

import com.czhappy.commonindexdemo.model.Classfly;

import com.czhappy.commonindexdemo.model.IndexBanner;

import com.czhappy.commonindexdemo.model.IndexBannerList;

import com.czhappy.commonindexdemo.okhttp.LoadingDialogCallback;

import com.czhappy.commonindexdemo.utils.AccordionTransformer;

import com.czhappy.commonindexdemo.utils.Api;

import com.czhappy.commonindexdemo.utils.NetworkImageHolderView;

import com.czhappy.commonindexdemo.utils.ToastUtil;

import com.czhappy.commonindexdemo.view.GridViewForScrollView;

import com.github.jdsjlzx.interfaces.OnLoadMoreListener;

import com.github.jdsjlzx.interfaces.OnRefreshListener;

import com.github.jdsjlzx.recyclerview.LRecyclerView;

import com.github.jdsjlzx.recyclerview.LRecyclerViewAdapter;

import com.github.jdsjlzx.recyclerview.ProgressStyle;

import com.lzy.okgo.OkGo;

import java.util.ArrayList;

import java.util.List;

import butterknife.BindView;

import butterknife.ButterKnife;

import okhttp3.Call;

import okhttp3.Response;

/**

* Description:

* User: chenzheng

* Date: 2016/9/9 0009

* Time: 17:18

*/

public class IndexFragment extends Fragment implements ViewPager.OnPageChangeListener{

@BindView(R.id.back_iv)

ImageView backIv;

@BindView(R.id.layout_back)

LinearLayout layoutBack;

@BindView(R.id.title_tv)

TextView titleTv;

@BindView(R.id.right_tv)

TextView rightTv;

@BindView(R.id.layout_right)

LinearLayout layoutRight;

@BindView(R.id.campaign_recyclerview)

LRecyclerView mRecyclerView;

private View mView;

private GridViewForScrollView classflyGridview;

private LinearLayout pointGroup;;

private ConvenientBanner convenientBanner;

private TextView bannerTitleTv;;

private List networkImages = new ArrayList();

private int lastPosition = 0;

private CampaignListAdapter campaignListAdapter;

private ClassflyListAdapter classflyListAdapter;

private IndexBannerList indexBannerList;

private CampaignList campaignList;

private LRecyclerViewAdapter mLRecyclerViewAdapter;

public int pageNum = 1;

public int pageSize = 4;

@Override

public View onCreateView(LayoutInflater inflater, ViewGroup container,

Bundle savedInstanceState) {

mView = inflater.inflate(R.layout.fragment_index, container,

false);

ButterKnife.bind(this, mView);

initView();

initClassfly();

return mView;

}

private void initView() {

backIv.setVisibility(View.GONE);

titleTv.setText("快知网");

layoutRight.setVisibility(View.INVISIBLE);

campaignListAdapter = new CampaignListAdapter(getActivity());

mLRecyclerViewAdapter = new LRecyclerViewAdapter(campaignListAdapter);

mRecyclerView.setAdapter(mLRecyclerViewAdapter);

mRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));

mRecyclerView.setRefreshProgressStyle(ProgressStyle.LineSpinFadeLoader);

mRecyclerView.setArrowImageView(R.drawable.ic_pulltorefresh_arrow);

mRecyclerView.setLoadingMoreProgressStyle(ProgressStyle.BallSpinFadeLoader);

//add a HeaderView

final View header = LayoutInflater.from(getActivity()).inflate(R.layout.index_header,(ViewGroup)mView.findViewById(android.R.i

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值