Skip to content
Related Articles

Related Articles

How to Display Medal in Android?
  • Last Updated : 23 Feb, 2021

Medal in Android is used to give a medal effect to your Android App. You can get to see this MedalView in most of the mobile games. Where this medal view is displayed after completing levels. Also, MedalView can be displayed in most of the coding sites for giving the ranking to the participants. In this article, we are going to learn how to display Medals on Android. A sample GIF is given below to get an idea about what we are going to do in this article.

Display Medal in Android

Applications of MedalLayout

  • This MedalLayout can be used in some of the apps to rank their participants who have scored more.
  • It can be used in most of the coding platform to rank their participants who have scored more points.
  • This Medal Layout can be seen in most of the games. In which the player is awarded by medal after the completion of the level.

Attributes of MedalLayout

Attributes

Description

directionThe direction of medal animation
speedSpeed of Medal animation 
degreeXRotation degree of X-axis
degreeYRotation degree of Y-axis
typeThe target of Medal Animation to View Group
autoStartMedal Animation starts automatically
loopLoop of Medal Animation
turnsNumber of turns per loop

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

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

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

implementation “com.github.skydoves:medal:1.0.4”

After adding dependency click on the “sync now” option on the top right corner to sync the project.

Step 3: Working with the activity_main.xml file

Go to the activity_main.xml file and refer to the following code. Below is the code for the activity_main.xml file.

XML




<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">
  
    <com.skydoves.medal.MedalLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:layout_weight="1"
        app:direction="right"
        app:speed="1500"
        app:turn="1">
          
        <ImageView
            android:layout_width="200dp"
            android:layout_height="200dp"
            android:scaleType="centerInside"
            android:src="@drawable/medal1" />
    </com.skydoves.medal.MedalLayout>
  
</RelativeLayout>

Output:

Want a more fast-paced & competitive environment to learn the fundamentals of Android?
Click here to head to a guide uniquely curated by our experts with the aim to make you industry ready in no time!
My Personal Notes arrow_drop_up
Recommended Articles
Page :