Table of contents |
|
ShimmerLayout in Android with Examples |
|
3. activity_main.xml |
|
4. Adding Code to MainActivity File |
|
MainActivity startShimmerAnimation |
|
Output: |
|
ShimmerLayout provides a visually appealing Shimmer Effect, akin to those seen on platforms like Facebook or LinkedIn, for Android applications. This layout proves especially useful when an application is fetching data from an API, a process that might take a while. In such cases, incorporating a ShimmerLayout is preferred over displaying a blank screen, as it informs the user that the layout is currently loading. The code examples are presented in both Java and Kotlin programming languages for Android.
ShimmerLayoutShimmer EffectFacebookLinkedInJava and Kotlin Programming Language for Android.1. Begin by integrating the support library into the App-level build.gradle file and subsequently add the necessary dependency within the dependencies section. This step enables developers to directly utilize the built-in functions.
1.build.gradle2. Proceed by creating a circle.xml file within the drawable folder and inserting the provided code snippet. This file will be utilized in conjunction with the ShimmerLayout alongside the text view.
2.circle.xml3. Finally, integrate the following code snippet into the activity_main.xml file. Within this file, include the ShimmerLayout and its respective child view. Attach circle.XML in the src tag within ImageView.
Code Snippet: | io.supercharge.shimmerlayout.ShimmerLayout xmlns:app="http://schemas.android.com/apk/res-auto" android:id="@id/shimmer_layout" android:layout_width="match_parent" android:layout_height="wrap_content" app:shimmer_animation_duration="2000" |
import android.os.Bundle; import androidx.appcompat.app.AppCompatActivity; import io.supercharge.shimmerlayout.ShimmerLayout; public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ShimmerLayout layout = findViewById(R.id.shimmer_layout); layout.startShimmerAnimation(); } }
import android.os.Bundle import androidx.appcompat.app.AppCompatActivity import io.supercharge.shimmerlayout.ShimmerLayout class MainActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) val layout: ShimmerLayout = findViewById(R.id.shimmer_layout) layout.startShimmerAnimation() } }
Java Implementation | Kotlin Implementation |
import android.os.Bundle; import androidx.appcompat.app.AppCompatActivity; import io.supercharge.shimmerlayout.ShimmerLayout; public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ShimmerLayout layout = findViewById(R.id.shimmer_layout); layout.startShimmerAnimation(); } } | import android.os.Bundle import androidx.appcompat.app.AppCompatActivity import io.supercharge.shimmerlayout.ShimmerLayout class MainActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) val layout: ShimmerLayout = findViewById(R.id.shimmer_layout) layout.startShimmerAnimation() } } |
Are you feeling overwhelmed in the expansive realm of Backend Development? It's time to make a significant shift! Enroll in our Java Backend Development - Live Course to commence an engaging journey towards mastering backend development efficiently and within the set timeline.
What's Included: