LayoutStatusControl
一個(gè)用于設(shè)置Layout不同狀態(tài)的class
優(yōu)點(diǎn)
- 使用非常簡(jiǎn)單,方便
- 無(wú)需修改已經(jīng)寫(xiě)好的xml布局(對(duì)半路要求新增樣式的項(xiàng)目尤其有用)
- 不會(huì)加深UI的層級(jí),從而導(dǎo)致過(guò)度繪制,卡頓等問(wèn)題
- 可以自定義自己的布局樣式
- 可對(duì)布局樣式設(shè)置監(jiān)聽(tīng)
- 可對(duì)任何View設(shè)置,不僅不局限與ListView or RecycleView
- 自動(dòng)繼承被替換的View的屬性,包括大小,位置,id(注意監(jiān)聽(tīng)問(wèn)題)等.
- 不會(huì)破壞被替換的View與其他View之間的依賴(lài)關(guān)系.(特別是相對(duì)布局)
背景
當(dāng)為L(zhǎng)istView設(shè)置一個(gè)空數(shù)據(jù)樣式時(shí),一般這么做:
<LinearLayout>
<ListView
android:id="@+id/list_sms_history"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scrollingCache="false" />
<TextView
android:id="@+id/noSmsData"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical|center_horizontal"
android:text="暫無(wú)數(shù)據(jù)" />
</LinearLayout>
callLogList = (ListView)findViewById(R.id.call_log_list);
myEmpty=(TextView)findViewById(R.id.myEmptyText);
callLogList.setEmptyView(myEmpty);
如果要為RecycleView設(shè)置一個(gè)空數(shù)據(jù)樣式時(shí),會(huì)更加復(fù)雜.
我們必須修改xml文件和java代碼,讓view可見(jiàn)與不可見(jiàn).
如果項(xiàng)目一開(kāi)始沒(méi)有對(duì)每個(gè)布局設(shè)置好空數(shù)據(jù)樣式時(shí),現(xiàn)在就需要對(duì)許多文件進(jìn)行設(shè)置,這可能會(huì)讓我們抓狂.
更加糟糕的是,現(xiàn)在需求改了,可能空數(shù)據(jù)的樣式不好看,需要換一個(gè)樣式,我們可能要檢查每一個(gè)布局.
雖然空數(shù)據(jù)的layout可能是統(tǒng)一的,但是有的xml布局可能特別復(fù)雜,以至于我們不得不檢查每一個(gè)修改的文件.
而且此時(shí)還可能會(huì)新增正在加載,錯(cuò)誤等樣式,這更加復(fù)雜...
LayoutStatusControl 能很好的幫助我們?cè)O(shè)置一個(gè)空數(shù)據(jù)樣式,甚至是其他的樣式,而且它非常的簡(jiǎn)單,方便.
修改樣式也特別的方便,而且它無(wú)需修改原有的xml,不會(huì)加深布局的層級(jí)導(dǎo)致UI過(guò)度繪制,卡頓問(wèn)題....
那么niubility,還不趕緊來(lái)試試.
使用方法
快速使用
//第一步:初始化,設(shè)置你想要替換的view的id
lyControl = new LayoutStatusControl(this, R.id.tv_content);
//第二步:設(shè)置一個(gè)空數(shù)據(jù)樣式.你可以設(shè)置一個(gè)layout或一個(gè)view
lyControl.setEmptyView(R.layout.view_nodata);
//第三步:展示
lyControl.showEmptyView();
更多功能
設(shè)置正在加載,空數(shù)據(jù),加載錯(cuò)誤,以及加載成功樣式
lyControl.showLoadingView();
lyControl.showEmptyView();
lyControl.showErrorView();
lyControl.showSuccessView();
自定義樣式界面
lyControl.setEmptyView();
lyControl.setErrorView();
lyControl.setLoadingView();
對(duì)界面設(shè)置監(jiān)聽(tīng)
lyControl.setEmptyListener();
lyControl.setErrorListener();
更多使用方法,可以看這個(gè)例子Example
問(wèn)題
如果你有任何問(wèn)題,你可以通過(guò) GitHub Issues提交.
LICENSE
Copyright 2017 The LayoutStatusControl authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.