RapidDevelop-Android快速開發(fā)框架
- 框架持續(xù)更新中
- 這個(gè)框架是從平時(shí)項(xiàng)目里用的比較多的框架里整合而來
- 對(duì)本項(xiàng)目感興趣的可以一起研究喜歡的朋友歡迎star
- 同時(shí)也歡迎大家的寶貴意見issues
- 如果大家對(duì)MVP模式的開發(fā) 網(wǎng)絡(luò)爬蟲以及緩存策略感興趣的話可以看看我最新寫的Freebook
- 源碼地址 功能還在繼續(xù)完善中 喜歡的朋友記得star
- 郵箱:mychinalance@gmail.com
- 下載APK
功能說明
- retrofit rxjava okhttp rxcache------------------------------網(wǎng)絡(luò)請(qǐng)求以及網(wǎng)絡(luò)緩存
- Demo采用MVP模式開發(fā)------------------------------------數(shù)據(jù)邏輯復(fù)用,便于維護(hù)升級(jí)
- 下拉刷新 上拉加載 及自動(dòng)加載---------------------------實(shí)現(xiàn)監(jiān)聽方便快捷
- RecyclerView設(shè)配器------------------------------------------再也不需要寫ViewHolder
- RecyclerView item加載動(dòng)畫--------------------------------多種動(dòng)畫效果一行代碼解決
- 頁面狀態(tài)統(tǒng)一管理 加載中 無數(shù)據(jù) 無網(wǎng)絡(luò)-------------所有頁面均可添加
- 圖片顯示與緩存 GIF圖片顯示
- Tab+Fragment快速實(shí)現(xiàn)
- 視頻播放(仿QQ空間,秒拍等List播放)
效果圖展示
使用說明
導(dǎo)入 lcrapiddeveloplibrary 到項(xiàng)目
在 build.gradle 的 dependencies 添加:
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
....
compile project(':lcrapiddeveloplibrary')
}
輕松實(shí)現(xiàn) 狀態(tài)頁面 下拉刷新 自動(dòng)加載 item動(dòng)畫
首先layout.xml里面的編寫啦 列表頁面基本都是這個(gè)套路
<!--ProgressActivity用于狀態(tài)頁的控制 比如加載中 網(wǎng)絡(luò)異常 無數(shù)據(jù) 適合任何頁面-->
<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里面的編寫了 這個(gè)例子里使用MVP模式編寫感興趣的看我最新寫的Freebook
public class ListvViewActivity extends AppCompatActivity implements BaseQuickAdapter.RequestLoadMoreListener,SpringView.OnFreshListener,SchoolListView {
RecyclerView mRecyclerView;
ProgressActivity progress;
private Toolbar toolbar;
private BaseQuickAdapter mQuickAdapter;
private int PageIndex=1;
private SpringView springView;
private SchoolListPresent present;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_listv_view);
initView();
}
private void initView() {
present = new SchoolListPresent(this);
mRecyclerView = (RecyclerView) findViewById(R.id.rv_list);
springView = (SpringView) findViewById(R.id.springview);
//設(shè)置下拉刷新監(jiān)聽
springView.setListener(this);
//設(shè)置下拉刷新樣式
springView.setHeader(new RotationHeader(this));
//springView.setFooter(new RotationFooter(this));mRecyclerView內(nèi)部集成的自動(dòng)加載 上啦加載用不上 在其他View使用
progress = (ProgressActivity) findViewById(R.id.progress);
//設(shè)置RecyclerView的顯示模式 當(dāng)前List模式
mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
//如果Item高度固定 增加該屬性能夠提高效率
mRecyclerView.setHasFixedSize(true);
//設(shè)置頁面為加載中..
progress.showLoading();
//設(shè)置適配器
mQuickAdapter = new ListViewAdapter(R.layout.list_view_item_layout,null);
//設(shè)置加載動(dòng)畫
mQuickAdapter.openLoadAnimation(BaseQuickAdapter.SCALEIN);
//設(shè)置是否自動(dòng)加載以及加載個(gè)數(shù)
mQuickAdapter.openLoadMore(6,true);
//將適配器添加到RecyclerView
mRecyclerView.setAdapter(mQuickAdapter);
//設(shè)置自動(dòng)加載監(jiān)聽
mQuickAdapter.setOnLoadMoreListener(this);
//請(qǐng)求網(wǎng)絡(luò)數(shù)據(jù)
present.LoadData(PageIndex,12,false);
}
//自動(dòng)加載
@Override
public void onLoadMoreRequested() {
PageIndex++;
present.LoadData(PageIndex,12,true);
}
//下拉刷新
@Override
public void onRefresh() {
PageIndex=1;
present.LoadData(PageIndex,12,false);
}
/*
* MVP模式的相關(guān)狀態(tài)
*
* */
@Override
public void showProgress() {
progress.showLoading();
}
@Override
public void hideProgress() {
progress.showContent();
}
@Override
public void newDatas(List<UniversityListDto> newsList) {
//進(jìn)入顯示的初始數(shù)據(jù)或者下拉刷新顯示的數(shù)據(jù)
mQuickAdapter.setNewData(newsList);//新增數(shù)據(jù)
mQuickAdapter.openLoadMore(10,true);//設(shè)置是否可以下拉加載 以及加載條數(shù)
springView.onFinishFreshAndLoad();//刷新完成
}
@Override
public void addDatas(List<UniversityListDto> addList) {
//新增自動(dòng)加載的的數(shù)據(jù)
mQuickAdapter.notifyDataChangedAfterLoadMore(addList, true);
}
@Override
public void showLoadFailMsg() {
//設(shè)置加載錯(cuò)誤頁顯示
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) {
PageIndex=1;
present.LoadData(PageIndex,12,false);
}
});
}
@Override
public void showLoadCompleteAllData() {
//所有數(shù)據(jù)加載完成后顯示
mQuickAdapter.notifyDataChangedAfterLoadMore(false);
View view = getLayoutInflater().inflate(R.layout.not_loading, (ViewGroup) mRecyclerView.getParent(), false);
mQuickAdapter.addFooterView(view);
}
@Override
public void showNoData() {
//設(shè)置無數(shù)據(jù)顯示頁面
progress.showEmpty(getResources().getDrawable(R.mipmap.monkey_cry),Constant.EMPTY_TITLE,Constant.EMPTY_CONTEXT);
}
}
輕松實(shí)現(xiàn)視頻列表播放
列表部分和上面的一樣就不說了,我這邊主要描敘視頻播放的部分 是在不懂得可以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="標(biāo)題"
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="內(nèi)容"
android:lines="3"
android:ellipsize="end"
android:layout_height="wrap_content"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
然后就是adapter里面對(duì)視頻控件的賦值處理
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動(dòng)圖
Glide.with(mContext)
.load(item.getPictureUrl())
.crossFade()
.placeholder(R.mipmap.def_head)
.into((ImageView) helper.getView(R.id.video_list_item_image));
//對(duì)視頻的賦值 添加視頻播放地址(使用原地址 .mp4之類的 這個(gè)要注意)和標(biāo)題
((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快速實(shí)現(xiàn)
還是原來的配方 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"
/>
完全可以按照自己想要的風(fēng)格玩 下面表格為 可設(shè)置的屬性
attr | 描述 |
---|---|
stl_indicatorAlwaysInCenter | 如果設(shè)置為真,有源標(biāo)簽總是顯示在中心(如報(bào)攤google app),默認(rèn)的錯(cuò)誤 |
stl_indicatorWithoutPadding | 如果設(shè)置為true,畫的指標(biāo)沒有填充選項(xiàng)卡中,默認(rèn)的錯(cuò)誤 |
stl_indicatorInFront | 畫前的指示器下劃線,默認(rèn)的錯(cuò)誤 |
stl_indicatorInterpolation | 行為的指標(biāo):“線性”或“智能” |
stl_indicatorGravity | 圖的位置指示器:“底”或“前”或“中心”,默認(rèn)“底” |
stl_indicatorColor | 標(biāo)志的顏色 |
stl_indicatorColors | 多種顏色的指標(biāo),可以設(shè)置每個(gè)選項(xiàng)卡的顏色 |
stl_indicatorThickness | 厚度指標(biāo) |
stl_indicatorWidth | 的寬度指標(biāo),默認(rèn)“汽車” |
stl_indicatorCornerRadius | 圓角半徑的指標(biāo) |
stl_overlineColor | 頂線的顏色 |
stl_overlineThickness | 頂線的厚度 |
stl_underlineColor | 顏色的底線 |
stl_underlineThickness | 厚度的底線 |
stl_dividerColor | 顏色之間的分隔器選項(xiàng)卡 |
stl_dividerColors | 多種顏色的選項(xiàng)卡之間的分隔器,可以設(shè)置每個(gè)選項(xiàng)卡的顏色 |
stl_dividerThickness | 分頻器的厚度 |
stl_defaultTabBackground | 背景可拉的每個(gè)選項(xiàng)卡其兴。 一般設(shè)置StateListDrawable |
stl_defaultTabTextAllCaps | 如果設(shè)置為真,所有選項(xiàng)卡標(biāo)題大寫,違約事實(shí) |
stl_defaultTabTextColor | 文本的顏色包括默認(rèn)的選項(xiàng)卡 |
stl_defaultTabTextSize | 文本包括默認(rèn)的選項(xiàng)卡的大小 |
stl_defaultTabTextHorizontalPadding | 文本布局填充默認(rèn)的選項(xiàng)卡包括 |
stl_defaultTabTextMinWidth | 最小寬度的標(biāo)簽 |
stl_customTabTextLayoutId | 布局ID定義自定義選項(xiàng)卡蠢涝。 如果你不指定一個(gè)布局,使用默認(rèn)選項(xiàng)卡 |
stl_customTabTextViewId | 文本視圖ID在一個(gè)自定義選項(xiàng)卡布局月匣。 如果你不與customTabTextLayoutId定義,不工作 |
stl_distributeEvenly | 如果設(shè)置為真,每個(gè)選項(xiàng)卡都給出同樣的重量,默認(rèn)的錯(cuò)誤 |
stl_clickable | 如果設(shè)置為false,禁用選擇選項(xiàng)卡單擊,違約事實(shí) |
stl_titleOffset | 如果設(shè)置為“auto_center”,中間的幻燈片的位置選項(xiàng)卡中心將繼續(xù)凌那。 如果指定一個(gè)維度將抵消從左邊緣,默認(rèn)24 dp |
stl_drawDecorationAfterTab | 畫裝飾(指示器和線)繪圖選項(xiàng)卡后,默認(rèn)的錯(cuò)誤 |
好了接下來就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("頭部顯示標(biāo)題", "建立的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);
}
}
功能還在繼續(xù)完善中感興趣的朋友可以一起
當(dāng)然也歡迎您提上寶貴的意見