Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Java Arrays
  • Java Strings
  • Java OOPs
  • Java Collection
  • Java 8 Tutorial
  • Java Multithreading
  • Java Exception Handling
  • Java Programs
  • Java Project
  • Java Collections Interview
  • Java Interview Questions
  • Java MCQs
  • Spring
  • Spring MVC
  • Spring Boot
  • Hibernate
Open In App
Next Article:
Shimmer Effect to Image in Android
Next article icon

Shimmer Effect to Image in Android

Last Updated : 23 Feb, 2021
Comments
Improve
Suggest changes
Like Article
Like
Report

Shimmer Effect is one of the most popular features that we see in most Android apps. We can get to see this Shimmer Effect while loading the screen in animated form. Using Shimmer Effect in the Android app makes a good User Experience. In this article, we are going to see how to implement the Shimmer Effect in the Android app. A sample GIF is given below to get an idea about what we are going to do in this article. Note that we are going to implement this project using the Java language. 

Applications of Shimmer Effect

  • Shimmer Effect is mostly used for loading the screen in an attractive form.
  • Shimmer Effect gives a good appearance to Images in the Android app.
  • Using Shimmer Effect in our app gives an Animated view of the image.

Step by Step Implementation

Step 1: Create a New Project

To create a new project in Android Studio please refer to How to Create/Start a New Project in Android Studio. Note that select Java as the programming language.

Step 2: Add dependency of Shimmer Effect library in build.gradle file

Then Navigate to gradle scripts and then to build.gradle(Module) level. Add below line in build.gradle file in the dependencies section.

implementation 'com.facebook.shimmer:shimmer:0.5.0'

now click on Sync now it will sync your all files in build.gradle().

Step 3: Create a new Shimmer Effect in your activity_main.xml file

Navigate to the app > res > layout > activity_main.xml and add the below code to that file. Below is the code for the activity_main.xml file. 

XML
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout      xmlns:android="http://schemas.android.com/apk/res/android"     xmlns:tools="http://schemas.android.com/tools"     android:layout_width="match_parent"     android:layout_height="match_parent"     android:background="@color/black"     android:paddingLeft="16dp"     android:paddingTop="16dp"     android:paddingRight="16dp"     android:paddingBottom="16dp"     tools:context=".MainActivity">      <!--Shimmer Effect-->     <com.facebook.shimmer.ShimmerFrameLayout         android:id="@+id/shimmer_view_container"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_centerInParent="true">          <LinearLayout             android:layout_width="wrap_content"             android:layout_height="wrap_content"             android:gravity="center"             android:orientation="vertical">              <!--Image-->             <ImageView                 android:layout_width="150dp"                 android:layout_height="150dp"                 android:src="@drawable/ic_baseline_account_balance_24" />              <!--Text given to Image-->             <TextView                 android:layout_width="wrap_content"                 android:layout_height="wrap_content"                 android:layout_marginTop="35dp"                 android:text="Bank"                 android:textColor="@color/purple_200"                 android:textSize="24dp"                 android:textStyle="bold" />                      </LinearLayout>      </com.facebook.shimmer.ShimmerFrameLayout>      <!--Button1 to start Shimmer Effect-->     <Button         android:id="@+id/button"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_alignParentStart="true"         android:layout_alignParentLeft="true"         android:layout_alignParentBottom="true"         android:paddingLeft="20dp"         android:text="Start" />      <!--Button2 to stop Shimmer Effect-->     <Button         android:id="@+id/button2"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_alignParentEnd="true"         android:layout_alignParentRight="true"         android:layout_alignParentBottom="true"         android:paddingRight="20dp"         android:text="Stop" />      </RelativeLayout> 

Step 4: Working with the MainActivity.java file

Go to the MainActivity.java file and refer to the following code. Below is the code for the MainActivity.java file. Comments are added inside the code to understand the code in more detail.

Java
import android.os.Bundle; import android.view.View; import android.widget.Button;  import androidx.appcompat.app.AppCompatActivity;  import com.facebook.shimmer.ShimmerFrameLayout;  public class MainActivity extends AppCompatActivity {      // Variables created for buttons and Shimmer     Button button1, button2;     ShimmerFrameLayout container;      @Override     protected void onCreate(Bundle savedInstanceState) {         super.onCreate(savedInstanceState);         setContentView(R.layout.activity_main);          button1 = findViewById(R.id.button);         button2 = findViewById(R.id.button2);          // Button 1 to start Shimmer Effect         button1.setOnClickListener(new View.OnClickListener() {             @Override             public void onClick(View v) {                 // If auto-start is set to false                 container.startShimmer();              }         });          // Button 2 to stop Shimmer Effect         button2.setOnClickListener(new View.OnClickListener() {             @Override             public void onClick(View v) {                 // If auto-start is set to false                 container.stopShimmer();              }         });          // Shimmer effect         container = (ShimmerFrameLayout) findViewById(R.id.shimmer_view_container);     } } 

Now click on the run option it will take some time to build Gradle. After that, you will get output on your device as given below.

Output:


Next Article
Shimmer Effect to Image in Android

C

chinmaymunje96
Improve
Article Tags :
  • Java
  • Technical Scripter
  • Android
  • Technical Scripter 2020
  • Android-Animation
Practice Tags :
  • Java

Similar Reads

    How to Create Shine Effect in Android?
    Shine Effect is used to give an ImageView, Button, or a View a better animation look. It is very easy to implement. A sample GIF is given below to get an idea about what we are going to do in this article. Note that we are going to implement this project using the Kotlin language.   Step by Step Imp
    3 min read
    Image Switcher in Android with Example
    Sometimes, you may not want an image to appear suddenly on the screen. Instead, you might prefer a smooth transition from one image to another using animation. Android offers a tool called ImageSwitcher to help with this. An ImageSwitcher lets you add simple transition effects to your images.What ar
    4 min read
    Auto Image Slider in Android with Example
    Auto Image Slider is one of the most seen UI components in Android. This type of slider is mostly seen inside the apps of big E-commerce sites such as Flipkart, Amazon, and many more. Auto Image Slider is used to represent data in the form of slides that change after a specific interval of time. In
    6 min read
    ShimmerLayout in Android with Examples
    ShimmerLayout can be used to add a Shimmer Effect to the Android Application. ShimmerLayout indicates to the user that content is loading and will improve the overall experience, providing a visual cue rather than just a blank screen. This is especially helpful during API data fetching or some other
    6 min read
    Scroll ImageView in Android
    In this article, we are going to implement a very important feature related to the ImageView. The image will keep on scrolling horizontally by itself. When we click on the image then it will stop scrolling and when we again click it will again keep scrolling. We can use this feature to show animatio
    3 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences