1. 程式人生 > >android快速開發框架--快速實現 頁面 載入中 載入失敗 無資料等狀態以及下拉重新整理和自動載入

android快速開發框架--快速實現 頁面 載入中 載入失敗 無資料等狀態以及下拉重新整理和自動載入

RapidDevelop-Android快速開發框架

  • 框架持續更新中
  • 這個框架是從平時專案裡用的比較多的框架裡整合而來
  • 對本專案感興趣的可以一起研究喜歡的朋友歡迎star
  • 同時也歡迎大家的寶貴意見issues
  • 如果大家對MVP模式的開發 網路爬蟲以及快取策略感興趣的話可以看看我最新寫的Freebook
  • 郵箱:[email protected]
  • 下載APK

功能說明

  • 當前最主流網路請求及請求資料快取(retrofit rxjava okhttp)
  • 下拉重新整理 上拉載入 及自動載入
  • RecyclerView設配器
  • RecyclerView item載入動畫
  • 頁面狀態統一管理 載入中 無資料 無網路
  • 圖片顯示與快取 GIF圖片顯示
  • Tab+Fragment快速實現
  • 視訊播放(仿QQ空間,秒拍等List播放)

效果圖展示

下拉重新整理 list分組 Grid顯示多佈局listview顯示視訊播放

使用說明

匯入 lcrapiddeveloplibrary 到專案

在 build.gradle 的 dependencies 新增:

dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
....
compile project(':lcrapiddeveloplibrary')
}

輕鬆實現 狀態頁面 下拉重新整理 自動載入 item動畫

首先layout.xml裡面的編寫啦 列表頁面基本都是這個套路

<!--ProgressActivity用於狀態頁的控制 比如載入中  網路異常  無資料  適合任何頁面-->
<com.xiaochao.lcrapiddeveloplibrary.viewtype.ProgressActivity
    xmlns:progressActivity="http://schemas.android.com/apk/res-auto"
    android:id="@+id/progress"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
>
<LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <!--SpringView下拉重新整理--> <com.xiaochao.lcrapiddeveloplibrary.widget.SpringView android:id="@+id/springview" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#FFFFFF" > <android.support.v7.widget.RecyclerView android:id="@+id/rv_list" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#eeeeee"/> </com.xiaochao.lcrapiddeveloplibrary.widget.SpringView> </LinearLayout> </com.xiaochao.lcrapiddeveloplibrary.viewtype.ProgressActivity>

然後就是Activity裡面的編寫了 這個例子裡面沒有使用MVP模式編寫感興趣的看我最新寫的Freebook

public class ListvViewActivity extends AppCompatActivity implements BaseQuickAdapter.RequestLoadMoreListener,SpringView.OnFreshListener {

    RecyclerView mRecyclerView;
    ProgressActivity progress;
    private Toolbar toolbar;
    private BaseQuickAdapter mQuickAdapter;
    private int PageIndex=1;
    private SpringView springView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_listv_view);
        initView();
        initListener();
    }
    private void initView() {
        mRecyclerView = (RecyclerView) findViewById(R.id.rv_list);
        springView = (SpringView) findViewById(R.id.springview);
        //設定下拉重新整理監聽
        springView.setListener(this);
        //設定下拉重新整理樣式
        springView.setHeader(new RotationHeader(this));
        //springView.setFooter(new RotationFooter(this));mRecyclerView內部整合的自動載入  上啦載入用不上   在其他View使用
        progress = (ProgressActivity) findViewById(R.id.progress);
        //設定RecyclerView的顯示模式  當前List模式
        mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
        //如果Item高度固定  增加該屬效能夠提高效率
        mRecyclerView.setHasFixedSize(true);
        //設定頁面為載入中..
        progress.showLoading();
        //設定介面卡
        mQuickAdapter = new ListViewAdapter(R.layout.list_view_item_layout,null);
        //設定載入動畫
        mQuickAdapter.openLoadAnimation(BaseQuickAdapter.SCALEIN);
        //設定是否自動載入以及載入個數
        mQuickAdapter.openLoadMore(6,true);
        //將介面卡新增到RecyclerView
        mRecyclerView.setAdapter(mQuickAdapter);
        //設定自動載入監聽
        mQuickAdapter.setOnLoadMoreListener(this);
        //請求網路資料
        initdate(PageIndex,false);
    }
   //自動載入
    @Override
    public void onLoadMoreRequested() {
        PageIndex++;
        initdate(PageIndex,true);
    }
    public void initdate(int PageIndex,final Boolean isJz){
        //獲取資料 網路請求使用 retrofit rxjava okhttp
        HttpData.getInstance().HttpDataToSchoolList(PageIndex, 12, new Observer<List<UniversityListDto>>() {
            @Override
            public void onCompleted() {
            }
            @Override
            public void onError(Throwable e) {
                //設定頁面為載入錯誤
                toError();
            }

            @Override
            public void onNext(List<UniversityListDto> universityListDtos) {
                if(isJz){
                    if(universityListDtos.size()==0){
                        //所有資料載入完成後顯示
                        mQuickAdapter.notifyDataChangedAfterLoadMore(false);
                        View view = getLayoutInflater().inflate(R.layout.not_loading, (ViewGroup) mRecyclerView.getParent(), false);
                        mQuickAdapter.addFooterView(view);
                    }else{
                        //新增自動載入的的資料
                        mQuickAdapter.notifyDataChangedAfterLoadMore(universityListDtos, true);
                    }
                }else{
                    if(universityListDtos.size()==0){
                        //設定頁面為無資料
                        toEmpty();
                    }else{
                        //進入顯示的初始資料或者下拉重新整理顯示的資料
                        mQuickAdapter.setNewData(universityListDtos);//新增資料
                        mQuickAdapter.openLoadMore(10,true);//設定是否可以下拉載入  以及載入條數
                        springView.onFinishFreshAndLoad();//重新整理完成
                        progress.showContent();
                    }
                }
            }
        });
    }
     //下拉重新整理
    @Override
    public void onRefresh() {
        PageIndex=1;
        initdate(PageIndex,false);
    }
    //上啦載入  mRecyclerView內部整合的自動載入  上啦載入用不上   在其他View使用
    @Override
    public void onLoadmore() {

    }
    //設定載入錯誤頁顯示
    public void toError(){
        try {
            mQuickAdapter.notifyDataChangedAfterLoadMore(false);
            View view = getLayoutInflater().inflate(R.layout.not_loading, (ViewGroup) mRecyclerView.getParent(), false);
            mQuickAdapter.addFooterView(view);
        } catch (Exception e) {
            e.printStackTrace();
        }
        progress.showError(getResources().getDrawable(R.mipmap.monkey_cry), Constant.ERROR_TITLE, Constant.ERROR_CONTEXT, Constant.ERROR_BUTTON, new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                progress.showLoading();
                initdate(1,false);
            }
        });
    }
    //設定無資料頁顯示
    public void toEmpty(){
        progress.showEmpty(getResources().getDrawable(R.mipmap.monkey_cry),Constant.EMPTY_TITLE,Constant.EMPTY_CONTEXT);
    }

}

輕鬆實現視訊列表播放

列表部分和上面的一樣就不說了,我這邊主要描敘視訊播放的部分 是在不懂得可以clone到本地倉庫跑一邊

item_layout.xml

<LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:padding="5dp"
        android:orientation="vertical">
        <com.xiaochao.lcrapiddeveloplibrary.Video.JCVideoPlayerStandard
            android:id="@+id/video_list_item_playr"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"/>
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="horizontal"
            android:padding="5dp"
            android:gravity="center_vertical">
            <ImageView
                android:id="@+id/video_list_item_image"
                android:layout_width="100dp"
                android:layout_height="70dp"
                android:src="@mipmap/def_head"/>
            <LinearLayout
                android:layout_width="0dp"
                android:layout_weight="1"
                android:layout_height="wrap_content"
                android:layout_marginLeft="15dp"
                android:layout_marginTop="5dp"
                android:layout_marginBottom="5dp"
                android:layout_marginRight="10dp"
                android:orientation="vertical">
                <TextView
                    android:id="@+id/video_list_item_text_title"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:textColor="#666666"
                    android:text="標題"
                    android:textSize="15dp"/>
                <TextView
                    android:id="@+id/video_list_item_text_context"
                    android:layout_width="wrap_content"
                    android:layout_marginTop="5dp"
                    android:textColor="#999999"
                    android:textSize="13dp"
                    android:text="內容"
                    android:lines="3"
                    android:ellipsize="end"
                    android:layout_height="wrap_content"/>
            </LinearLayout>
        </LinearLayout>

    </LinearLayout>

然後就是adapter裡面對視訊控制元件的賦值處理

public class VideoLisViewAdapter extends BaseQuickAdapter<VideoListDto> {

    public VideoLisViewAdapter(int layoutResId, List<VideoListDto> data) {
        super(layoutResId, data);
    }

    public VideoLisViewAdapter(List<VideoListDto> data) {
        super(data);
    }

    public VideoLisViewAdapter(View contentView, List<VideoListDto> data) {
        super(contentView, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, VideoListDto item) {
        helper.setText(R.id.video_list_item_text_title,item.getTitle()).setText(R.id.video_list_item_text_context,item.getIntroduction());
        //Glide載入圖片  並且支援gif動圖
        Glide.with(mContext)
                .load(item.getPictureUrl())
                .crossFade()
                .placeholder(R.mipmap.def_head)
                .into((ImageView) helper.getView(R.id.video_list_item_image));
        //對視訊的賦值 新增視訊播放地址(使用原地址  .mp4之類的  這個要注意)和標題
        ((JCVideoPlayerStandard)helper.getView(R.id.video_list_item_playr)).setUp(item.getAppVideoUrl(),item.getTitle());
        Glide.with(mContext)
                .load(item.getPictureUrl())
                .crossFade()
                .placeholder(R.mipmap.main_mini_m)
                .into((((JCVideoPlayerStandard) helper.getView(R.id.video_list_item_playr)).thumbImageView));
    }
}

Tab+Fragment快速實現

還是原來的配方 layout.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical"
    tools:context="com.xiaochao.lcrapiddevelop.UI.Tab.TabActivity">
    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        app:popupTheme="@style/AppTheme.PopupOverlay" />
    <!--顯示頭部滑塊-->
    <FrameLayout
        android:id="@+id/tab"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#fff"
        />
    <android.support.v4.view.ViewPager
        android:id="@+id/viewpager"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        />
</LinearLayout>

然後就是頭部的xml編寫了

<com.xiaochao.lcrapiddeveloplibrary.SmartTab.SmartTabLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/viewpagertab"
    android:layout_width="match_parent"
    android:layout_height="40dp"
    android:background="#FFFFFF"

    app:stl_defaultTabTextColor="@color/custom_tab"
    app:stl_distributeEvenly="true"
    app:stl_defaultTabTextHorizontalPadding="5dp"
    app:stl_indicatorColor="@color/title_bag"
    app:stl_indicatorCornerRadius="0dp"
    app:stl_indicatorInterpolation="smart"
    app:stl_indicatorThickness="3dp"
    app:stl_defaultTabTextSize="13dp"
    app:stl_dividerColor="@color/bag_gray"
    app:stl_dividerThickness="1dp"
    app:stl_overlineColor="@color/bag_gray"
    app:stl_underlineColor="#00000000"
    app:stl_defaultTabBackground="@color/bag_gray_transparent"
    />

完全可以按照自己想要的風格玩 下面表格為 可設定的屬性

attr 描述
stl_indicatorAlwaysInCenter 如果設定為真,有源標籤總是顯示在中心(如報攤google app),預設的錯誤
stl_indicatorWithoutPadding 如果設定為true,畫的指標沒有填充選項卡中,預設的錯誤
stl_indicatorInFront 畫前的指示器下劃線,預設的錯誤
stl_indicatorInterpolation 行為的指標:“線性”或“智慧”
stl_indicatorGravity 圖的位置指示器:“底”或“前”或“中心”,預設“底”
stl_indicatorColor 標誌的顏色
stl_indicatorColors 多種顏色的指標,可以設定每個選項卡的顏色
stl_indicatorThickness 厚度指標
stl_indicatorWidth 的寬度指標,預設“汽車”
stl_indicatorCornerRadius 圓角半徑的指標
stl_overlineColor 頂線的顏色
stl_overlineThickness 頂線的厚度
stl_underlineColor 顏色的底線
stl_underlineThickness 厚度的底線
stl_dividerColor 顏色之間的分隔器選項卡
stl_dividerColors 多種顏色的選項卡之間的分隔器,可以設定每個選項卡的顏色
stl_dividerThickness 分頻器的厚度
stl_defaultTabBackground 背景可拉的每個選項卡。 一般設定StateListDrawable
stl_defaultTabTextAllCaps 如果設定為真,所有選項卡標題大寫,違約事實
stl_defaultTabTextColor 文字的顏色包括預設的選項卡
stl_defaultTabTextSize 文字包括預設的選項卡的大小
stl_defaultTabTextHorizontalPadding 文字佈局填充預設的選項卡包括
stl_defaultTabTextMinWidth 最小寬度的標籤
stl_customTabTextLayoutId 佈局ID定義自定義選項卡。 如果你不指定一個佈局,使用預設選項卡
stl_customTabTextViewId 文字檢視ID在一個自定義選項卡布局。 如果你不與customTabTextLayoutId定義,不工作
stl_distributeEvenly 如果設定為真,每個選項卡都給出同樣的重量,預設的錯誤
stl_clickable 如果設定為false,禁用選擇選項卡單擊,違約事實
stl_titleOffset 如果設定為“auto_center”,中間的幻燈片的位置選項卡中心將繼續。 如果指定一個維度將抵消從左邊緣,預設24 dp
stl_drawDecorationAfterTab 畫裝飾(指示器和線)繪圖選項卡後,預設的錯誤

好了接下來就TabActivity

public class TabActivity extends AppCompatActivity {

    ViewGroup tab;
    ViewPager viewpager;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_tab);
        initView();
    }

    private void initView() {
        tab = (ViewGroup) findViewById(R.id.tab);
        viewpager = (ViewPager) findViewById(R.id.viewpager);
        //使用方才定義頭部
        tab.addView(LayoutInflater.from(this).inflate(R.layout.tab_top_layout, tab, false));

        SmartTabLayout viewPagerTab = (SmartTabLayout) findViewById(R.id.viewpagertab);

        FragmentPagerItems pages = new FragmentPagerItems(this);

        //新增Fragment  FragmentPagerItem.of("頭部顯示標題", "建立的fragment","需要傳值的可以傳Bundle")
        for (int i=0;i<4;i++) {
            pages.add(FragmentPagerItem.of("Tab"+i, TabFragment.class));
        }

        FragmentPagerItemAdapter adapter = new FragmentPagerItemAdapter(
                getSupportFragmentManager(), pages);

        viewpager.setAdapter(adapter);
        viewPagerTab.setViewPager(viewpager);
    }
}

相關推薦

android快速開發框架--快速實現 頁面 載入 載入失敗 資料狀態以及重新整理自動載入

RapidDevelop-Android快速開發框架 框架持續更新中 這個框架是從平時專案裡用的比較多的框架裡整合而來 對本專案感興趣的可以一起研究喜歡的朋友歡迎star 同時也歡迎大家的寶貴意見issues 如果大家對MVP模式的開發 網路爬蟲以及快取策略

RecyclerView實現重新整理自動載入控制元件封裝

CommonAdapter.java public abstract class CommonAdapter<T> extends RecyclerView.Adapter<ViewHolder> { protected Context mContext; prot

重新整理自動載入側滑選單的RecyclerView基本實現原理

目錄 目錄 前言 結尾 前言   現在這個功能的框架也挺多的了。之所以要寫是因為這個框架是自己親手實現的。說起來有點小激動,這是我正經寫出來的第一個框架。對於”不要重複造輪子”這句話,我一直不是太認同,得從不同的維度看。如果從使用上

使用jquery-weui製作的重新整理滾動載入

一、前期檔案中引入weui.min.css,jquery-weui.min.css,jquery-2.1.4.js,jquery-weui.min.js,fastclick.js這些檔案。 二、html程式碼 <head> <meta charset="utf-8

優雅地為RecyclerView加上頭部、重新整理自動載入

一、概述 我們在寫專案的時候,永遠都離不開ListView、RecyclerView這類的控制元件,幾乎是在任何的APP中都可以看到他們的影子,但是RecyclerView並沒有像ListView提供了addHeadView、addFooterView

基於 MVP 架構使用Android通用開發框架快速開發微博項目實戰

安卓 MVP 課程目標:基於 MVP 架構使用Android通用開發框架快速開發微博項目實戰適應人群:適合大學生和初中級android開發工程師,可以系統化的微博類APP的開發,系統化掌握商業化項目的開發。* 不斷豐富自己的知識,做有“錢”途的Android工程師課程簡介:《基於 MVP 架構使用An

iOS開發-ios7重新整理 上提載入快速整合

                在ios7之前,一直在使用開源的EGO庫。但是,在使用過程中發現,普遍封裝得過於複雜、耦合性強,不利於整合到自己的專案中。另外,在ios7之後,一些原有的下拉重新整理,上提載入控制元件表現的就不是那麼出色了。除了可能出錯外,也不符合扁平化的風格。後來,在code4App上發現了

畢業設計之android混合模式開發第一天--具有重新整理頁面載入等待的WebView搭建

第一次真正接觸android的混合模式開發,之前瞭解過如何進行混合模式的開發,常見的是通過WebView元件載入url,使用HTML5和CSS3構建手機端響應式佈局。 今天主要是搭建出一個可載入url,具有下拉重新整理和頁面等待的WebView。 2.頁面等待的實現主要是

當scrollview巢狀多個recyclerview時如何實現整個頁面重新整理載入

最近做的一個專案中有個佈局比較複雜一點,整個頁面是個srollview裡面又嵌套了幾個recycview,剛開始是有的滑動衝突卡頓的問題,通過如下方法解決了 mRecyclerView.setLayoutManager(new GridLayoutManager(getContext(),

微信小程式開發列表頁載入一頁以及重新整理 實現方法

 微信小程式開發中列表頁載入下一頁以及下拉重新整理 實現方法,微信列表頁常用功能有下拉重新整理,上劃載入更多,怎麼實現呢? 直接上程式碼吧: 列表頁js global.p = 1 var url = getApp().globalData.API_URL +'/a

andbase框架實現載入重新整理自定義旋轉動畫的方式

1、今天做列表時,需求上需要做一個下拉重新整理,下拉載入更多的功能,就上網找了一些例子,由於我原來用的就是andbase框架,就還是用它原來寫的了。其中同事給我推薦另一個框架BGARefreshLayout-Android,下載地址https://github.com/bin

Android打造 ListView GridView 通用的重新整理自動載入的元件

分享一下我老師大神的人工智慧教程!零基礎,通俗易懂!http://blog.csdn.net/jiangjunshow 也歡迎大家轉載本篇文章。分享知識,造福人民,實現我們中華民族偉大復興!        

史上最全的使用RecyclerView實現重新整理載入更多

前言:            縱觀多數App,下拉重新整理和上拉載入更多是很常見的功能,但是谷歌官方只有一個SwipeRefreshLayout用來下拉重新整理,上拉載入更多還要自己做。      本篇文章基於RecyclerView簡單封裝了這兩個操作,下拉重

android smartRefresh重新整理載入

1.遠端依賴  compile 'com.scwang.smartrefresh:SmartRefreshLayout:1.0.5.1' 2.佈局中使用 <com.scwang.smartrefresh.layout.SmartRefreshLayout androi

Android重新整理載入

先看看XML佈局檔案,下拉重新整理和上拉載入哪個在外層並沒有什麼影響。最裡面嵌套了一個RecycleView。 <android.support.v4.widget.SwipeRefreshLayout     android:id="@+id/gridswipre

template-web.js 結合dropload.min.js外掛實現重新整理載入

//引入js,所需要的js已經上傳到個人資源 <script type="text/javascript" src="/web/home/js/template-web.js"></script> <link href="/web/h

android自定義重新整理載入控制元件

import android.content.Context; import android.graphics.Point; import android.support.v4.view.MotionEventCompat; import android.support.v4.view.NestedScro

自定義ListView實現重新整理載入

實現ListView的下拉重新整理和上拉載入,需要先新增headerView和footerView,通過在拖動的過程中,控制頭尾佈局的paddingTop實現。先把paddingTop設為負值,來隱藏header,在下拉的過程中,不斷改變headerView的p

Flutter如何實現重新整理載入更多

效果 下拉重新整理 如果實現下拉重新整理,必須藉助RefreshIndicator,在listview外面包裹一層RefreshIndicator,然後在RefreshIndicator裡面實現onRefresh方法。 body: movie

Android分組列表懸停顯示,分組listView懸停效果,帶重新整理載入更多

分組列表,帶下拉重新整理和上拉載入更多【專案地址在文章最後!!】 效果圖: 實現過程,借鑑PinnedHeadListView,但是該demo沒有下拉重新整理功能,故將該控制元件整合到PullToRefresh 庫中,【PullToRefresh 庫為第