Giter VIP home page Giter VIP logo

statelayout's Introduction

StateLayout

A custom layout that can easily switch different states(like empty,error,progress,content) with animations.

gif

Usage

Add the dependencies to your project:

gradle

	dependencies {
    	compile 'com.lufficc:stateLayout:0.0.5'
	}

maven

	<dependency>
      <groupId>com.lufficc</groupId>
      <artifactId>stateLayout</artifactId>
      <version>0.0.5</version>
      <type>pom</type>
    </dependency>

Ivy

	<dependency org='com.lufficc' name='stateLayout' rev='0.0.5'>
      <artifact name='$AID' ext='pom'></artifact>
    </dependency>

Add StateLayout to your layout file

Remember ,StateLayout can only hold one direct child

    <?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>

operation in 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

custom

attrs

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

    etEmptyAction(OnClickListener onEmptyButtonClickListener); // //set a callback called where empty view is clicked

Animation

you can custom your own animation by implements ViewAnimProvider interface,

by default,there are two simple animations, FadeViewAnimProvider and FadeScaleViewAnimProvider

public interface ViewAnimProvider {
    void onHideAndShow(@Nullable View willHide, @NonNull View willShow);
}


stateLayout.setViewSwitchAnimProvider(new FadeViewAnimProvider()); //user it

if you find a bug or have good suggestion ,find me here https://lufficc.com

License

Copyright 2016 Copyright 2016 lufficc

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.

statelayout's People

Contributors

lufficc avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.