From 843f046019d9e6ad97064b68b5bc6403213f83ad Mon Sep 17 00:00:00 2001 From: Jacek Date: Tue, 24 Nov 2015 15:19:54 +0100 Subject: [PATCH] Update README.md --- README.md | 101 +++++++++++++++++++++++++----------------------------- 1 file changed, 47 insertions(+), 54 deletions(-) diff --git a/README.md b/README.md index cf5c9ea..71677b4 100644 --- a/README.md +++ b/README.md @@ -1,84 +1,78 @@ [![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-Switcher-brightgreen.svg?style=flat)](https://android-arsenal.com/details/1/2603) # What is it? -Library that allows you to eaisly switch between your content, progress, error and blur view. It does it with smooth crossfade animation. It also lets you add on click listener to the error view. - You only show content, progress or error view. The switcher finds out what's currently visible and hides it. +Library that allows you to eaisly switch between your content, progress, empty placeholder view. It does it with smooth crossfade animation. It also lets you add on click listener to the error view. + You only show content, progress or error view. The switcher finds out what's currently visible and hides it. You can hide/show multiple views at once. #How to use it? -1) Build your layout like this. It's important to pack your content, progress and error view into the same ```FrameLayout```. It won't work otherwise. +1) It's important that all parent views of the layout arr registered with switcher as progress, error or empty view. +Here is example layout: ```xml - - - - + - <-- your empty placeholder subviews goes here --> - - - - + - <-- your progress subviews goes here --> + - + - + android:layout_height="wrap_content" + android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"> - <-- your error subviews goes here --> + - + - + app:layout_behavior="@string/appbar_scrolling_view_behavior" /> - <-- your content goes here --> - - - - - + + + + ``` 2) Build your switcher (if you use it from activity, ```onCreate()``` will be the good place, if it's a fragment, use ```onCreateView()```) ```java -switcher = new Switcher.Builder() - .withContentView(findViewById(R.id.content)) //ViewGroup holding your main content - .withErrorView(findViewById(R.id.error_view)) //ViewGroup holding your error view - .withProgressView(findViewById(R.id.progress_view)) //ViewGroup holding your progress view - .withBlurView(findViewById(R.id.blur_view)) //View overlaying another view, that you'd like to blur - .withErrorLabel((TextView) findViewById(R.id.error_label)) // TextView within your error ViewGroup that you want to change - .withProgressLabel((TextView) findViewById(R.id.progress_label)) // TextView within your progress ViewGroup that you want to change - .withEmptyView(findViewById(R.id.empty_view)) //SOme empty placeholder we display on lists for example if there are no results + switcher = new Switcher.Builder(this) + .addContentView(findViewById(R.id.recycler_view)) //content member + .addContentView(findViewById(R.id.fab)) //content member + .addErrorView(findViewById(R.id.error_view)) //error view member + .addProgressView(findViewById(R.id.progress_view)) //progress view member + .setErrorLabel((TextView) findViewById(R.id.error_label)) // TextView within your error member group that you want to change + .setProgressLabel((TextView) findViewById(R.id.progress_label)) // TextView within your progress member group that you want to change + .addEmptyView(findViewById(R.id.empty_view)) //empty placeholder member .build(); ``` @@ -88,7 +82,6 @@ switcher.showContentView(); switcher.showProgressView(); switcher.showErrorView(); switcher.showEmptyView(); -switcher.showBlurView(View viewToBlur); ``` If you rather switch views immediately without animation use ```showProgressViewImmediately()``` and corresponding for other states.