StateLayout
介绍:
一个多状态布局,可以在 empty,error,progress,content之间切换,并带动画效果。
运行效果:
使用说明:
gradle
dependencies {
compile 'com.lufficc:stateLayout:0.1.1'
}
记住,StateLayout只能有一个直接子view
<?xml version="1.0" encoding="utf-8"?>
<com.lufficc.stateLayout.StateLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/stateLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.lcc.demo.statelayout.MainActivity">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:padding="10dp"
android:layout_gravity="center_horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@mipmap/avatar" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:textSize="18sp"
android:text="@string/demo" />
</FrameLayout>
</com.lufficc.stateLayout.StateLayout>
在java代码中
stateLayout.showErrorView(); //switch to error view
stateLayout.showErrorView(msg); //switch to error view with a message
stateLayout.showEmptyView(); //switch to empty view
stateLayout.showEmptyView(msg); //switch to empty view with a message
stateLayout.showProgressView(); //switch to progress view
stateLayout.showProgressView(msg); //switch to progress view with a message
stateLayout.showContentView(); //switch to your content view
动画
你可以通过实现ViewAnimProvider接口来自定义动画,默认有两个简单的动画,FadeViewAnimProvider 和 FadeScaleViewAnimProvider
public interface ViewAnimProvider {
Animation showAnimation();
Animation hideAnimation();
}
//or
stateLayout.setHideAnimation(yourAnimation);
stateLayout.setShowAnimation(yourAnimation);
stateLayout.setViewSwitchAnimProvider(new FadeViewAnimProvider()); //user it
属性
attr | for |
---|---|
app:errorDrawable | custom the error drawable |
app:emptyDrawable | custom the empty drawable |
app:progressView | custom your own progress view |
|
listener
setErrorAction(OnClickListener onErrorButtonClickListener); //set a callback called where error view is clicked,
// you can tetry load data,for example
setEmptyAction(OnClickListener onEmptyButtonClickListener); // //set a callback called where empty view is clicked
已下载
0