Sunday, October 10, 2021

A wrapper view for your layouts different loading states

 Usage

Add it to your XML layout and add in your various layouts as direct children of LoadingLayout.

Make sure to add in android:tag to your elements corresponding to what you'd like them to represent:

Your layout should end up looking something like this:

<com.valartech.loadinglayout.LoadingLayout

        android:layout_width="match_parent"

        android:layout_height="match_parent"

        >

        <!--  Empty      -->

        <TextView

            android:tag="@string/ll_empty"            

            ...

            />


        <!--   Loading     -->

        <ProgressBar

            android:layout_width="wrap_content"

            android:layout_height="wrap_content"

            android:layout_gravity="center"

            android:tag="@string/ll_loading" />


        <!--   Completed     -->

        <FrameLayout

            android:layout_width="match_parent"

            android:layout_height="match_parent"

            android:tag="@string/ll_complete">

          ...

        </FrameLayout>


        <!--    Error    -->

        <TextView

            android:layout_width="match_parent"

            android:layout_height="match_parent"

            android:tag="@string/ll_error"

            android:text="@string/error"

            />

    </com.valartech.loadinglayout.LoadingLayout>

And now chunks of code like this:

loadingView?.visibility = View.VISIBLE

completeView?.visibility = View.GONE

emptyView?.visibility = View.GONE

errorView?.visibility = View.GONE

can be replaced by loadingLayout.setState(LOADING)

Adding to your project

//in your project-level build.gradle

allprojects {

    repositories { //not under buildscript

        maven { url "https://jitpack.io" } 

    }

}


//in your app module's build.gradle

dependencies {

    implementation "com.valartech:loading-layout:${version}"

}

Custom XML attributes

Tips

You're free to use a single view (like a ProgressBar) or a container of views(like a ConstraintLayout) as a child of the LoadingLayout.

The LOADING_OVERLAY is a special state that shows the loading state over the completed state, with a tint applied over it. It also prevents button clicks from reaching the completed layout.

Use tools:default_state to quickly check how different view states would look within your layout.

Caveat

This library does add in an extra view into your layout hierarchy, and would thus cause a slight hit in performance. We have not seen this be a noticeable issue in our apps even on complex views, but use as per your discretion on deeply nested layouts.

GitHub

https://github.com/valartech/loading-layout

2 comments:


  1. Thanks for this information. it is helpfull and worthy
    Laptop Repair Center offers quality service for your laptop at a reasonable cost. We offer doorstep support, 24*7 onsite support, repair all brand laptops, have an expert team for onsite support, and much more. for more contact us on 7291903784
    laptop repair center in Delhi

    ReplyDelete
  2. i found it very helpful. thank u

    Mast Banarasi Paan is one of the best selling paan such as Rajwadi paan, Laddu paan, Choclate Paan, Fire paan, Silver paan. Mast Banarasi Paan is made available to every customer with unique flavor, quality taste, and hygiene and we are the best paan provider in India.
    banarasi paan

    ReplyDelete