A custom layout that can easily switch different states(like empty,error,progress,content) with animations.
This library has been inspired by lufficc/iShuiHui
From Source
- For using StateLayout module in sample app, include the source code and add the below dependencies in entry/build.gradle to generate hap/support.har.
implementation project(path: ':stateLayout')
- For using StateLayout module in separate application using har file, add the har file in the entry/libs folder and add the dependencies in entry/build.gradle file.
implementation fileTree(dir: 'libs', include: ['*.har'])
<?xml version="1.0" encoding="utf-8"?>
<com.lufficc.statelayout.StateLayout
xmlns:ohos="http://schemas.huawei.com/res/ohos"
ohos:id="$+id:stateLayout"
ohos:height="match_parent"
ohos:width="match_parent" >
<DirectionalLayout
ohos:height="match_parent"
ohos:width="match_parent"
ohos:alignment="center">
<Image
ohos:height="match_content"
ohos:width="match_content"
ohos:image_src="$media:avatar"
ohos:layout_alignment="horizontal_center"/>
<Text
ohos:height="match_content"
ohos:width="match_content"
ohos:multiple_lines="true"
ohos:text="Hello World! I am content view."
ohos:text_size="$float:text_size"
/>
</DirectionalLayout>
</com.lufficc.statelayout.StateLayout>
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 viewyou can custom your own animation by implements ViewAnimProvider interface,
by default,there are two simple animations, FadeViewAnimProvider and FadeScaleViewAnimProvider
public interface ViewAnimProvider {
AnimatorProperty showAnimation();
AnimatorProperty 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 |
setErrorAction(ClickedListener onErrorButtonClickedListener ); // set a callback called where error view is clicked,
// you can retry, load data,for example
setEmptyAction(ClickedListener onEmptyClickedListener ); // set a callback called where empty view is clickedTake a look at the sample project for more information.
Check the LICENSE file

