Open top menu

Make Square GridView Cells Height and Width in android?






In this blog we will explain how to implement square gridview cells in GridView Layout. The GridView Cells measuring height and width automatically.

Step:1 create imageview class inside src folder .
...................................................................................................................................................................

public class SquareImageView extends ImageView {
public SquareImageView(Context context)
   {
       super(context);
   }

   public SquareImageView(Context context, AttributeSet attrs)
   {
       super(context, attrs);
   }

   public SquareImageView(Context context, AttributeSet attrs, int defStyle)
   {
       super(context, attrs, defStyle);
   }

   @Override
   protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
   {
       super.onMeasure(widthMeasureSpec, heightMeasureSpec);
       
       setMeasuredDimension(getMeasuredWidth(), getMeasuredWidth());  
   }

}

Step:2 create griview cell view class inside res/layout folder.
gridview_item,xml
...................................................................................................................................................................

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#ffffff">
    
    <com.example.androidtestcode.SquareImageView
        android:id="@+id/picture"
        android:layout_width="match_parent"
        android:layout_height="match_parent" 
        android:scaleType="fitXY"
        android:padding="10dp"
        android:background="@drawable/border" />       
</FrameLayout>


Step:3 create expandable gridview class inside src folder..

ExpandableHeightGridView .java
...................................................................................................................................................................



public class ExpandableHeightGridView extends GridView {

boolean expanded = false;

public ExpandableHeightGridView(Context context)
{
    super(context);
}

public ExpandableHeightGridView(Context context, AttributeSet attrs)
{
    super(context, attrs);
}

public ExpandableHeightGridView(Context context, AttributeSet attrs,
        int defStyle)
{
    super(context, attrs, defStyle);
}

public boolean isExpanded()
{
    return expanded;
}

@Override
public void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
{
    // HACK! TAKE THAT ANDROID!
    if (isExpanded())
    {
        // Calculate entire height by providing a very large height hint.
        // View.MEASURED_SIZE_MASK represents the largest height possible.
        int expandSpec = MeasureSpec.makeMeasureSpec(MEASURED_SIZE_MASK,
                MeasureSpec.AT_MOST);
        super.onMeasure(widthMeasureSpec, expandSpec);

        ViewGroup.LayoutParams params = getLayoutParams();
        params.height = getMeasuredHeight();
    }
    else
    {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    }
}

public void setExpanded(boolean expanded)
{
    this.expanded = expanded;
} }


Step:3create main xml class inside res/layout folder.
activity_main.xml.
...................................................................................................................................................................

<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="#000000"
    android:gravity="center"
     >

    <com.example.androidtestcode.ExpandableHeightGridView
        android:id="@+id/gridview"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:verticalSpacing="4dp"
        android:horizontalSpacing="4dp"   
        android:stretchMode="columnWidth"               
        android:numColumns="3"
        android:layout_margin="3dp"
        android:direction="top_to_bottom|left_to_right"
       />
</RelativeLayout>




Step:4 create gridview adatpter class inside src folder.
Adapter.java.
...................................................................................................................................................................


public class Adapter  extends BaseAdapter{
private List<Item> items = new ArrayList<Item>();
     private LayoutInflater inflater;

     public Adapter(Context context)
     {
         inflater = LayoutInflater.from(context);
         items.add(new Item("Image 1", R.drawable.logo));
         items.add(new Item("Image 2", R.drawable.logo));
         items.add(new Item("Image 3", R.drawable.logo));
         items.add(new Item("Image 4", R.drawable.logo));
         items.add(new Item("Image 5", R.drawable.logo));
         items.add(new Item("Image 6", R.drawable.logo));
         items.add(new Item("Image 7", R.drawable.logo));
         items.add(new Item("Image 8", R.drawable.logo));
         items.add(new Item("Image 9", R.drawable.logo));
     }

     @Override
     public int getCount() {
         return items.size();
     }

     @Override
     public Object getItem(int i)
     {
         return items.get(i);
     }

     @Override
     public long getItemId(int i)
     {
         return items.get(i).drawableId;
     }

     @SuppressLint("NewApi")
@Override
     public View getView(int i, View view, ViewGroup viewGroup)
     {
         View v = view;
         SquareImageView picture;
         

         if(v == null)
         {
            v = inflater.inflate(R.layout.gridview_item, viewGroup, false);
            v.setTag(R.id.picture, v.findViewById(R.id.picture));
            v.setBottom(23);
         }

         picture = (SquareImageView)v.getTag(R.id.picture);
         

         Item item = (Item)getItem(i);

         picture.setImageResource(item.drawableId);
        
         

         return v;
     }

     private class Item
     {
          
         final int drawableId;

         Item(String name, int drawableId)
         {
             
             this.drawableId = drawableId;
         }
     }
 }


Step:5 create main java class inside src folder.
MainActivity.java.
...................................................................................................................................................................

public class MainActivity extends  Activity {
ExpandableHeightGridView gridView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
 
gridView = (ExpandableHeightGridView) findViewById(R.id.gridview);
 
gridView.setAdapter(new Adapter(this));
 }
}


Read more

 How to Add fragmnet In Activity programmatically in android?


In this blog we will explain Step by Step how to Add fragment in Activity . Show below

Step 1: create MainActivtiy  class in src folder...
MainActivity.java
...................................................................................................................................................................

package com.androidbeginner.testcode;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.LinearLayout;

@SuppressLint("ResourceAsColor")
public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getActionBar().setTitle("Add Fragment");
setContentView(R.layout.activity_main);
final LinearLayout frgmentss=(LinearLayout)findViewById(R.id.fragment);
Button btnfragmnet=(Button)findViewById(R.id.button1);
btnfragmnet.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// get an instance of FragmentTransaction from your Activity
      FragmentManager fragmentManager = getFragmentManager();
      FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();

      //add a fragment
      TestFragmnet myFragment = new TestFragmnet();
      fragmentTransaction.add(frgmentss.getId(), myFragment);
      fragmentTransaction.commit();
}
});
 
}

}
...................................................................................................................................................................


Step 2: create activity_main xml class inside res/layout folder
activity_main.xml.
.................................................................................................................................................................
<LinearLayout 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:orientation="vertical"
    android:gravity="center"
    android:id="@+id/fragment" >

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Add Fragment" />

</LinearLayout>
...................................................................................................................................................................

Step 3.create fragmnet view xml class inside res/layout folder.
fragmnet_layout.xml
...................................................................................................................................................................

<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:orientation="vertical"
    android:background="#ffffff">

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:src="@drawable/logoweb" />
        
</RelativeLayout>
...................................................................................................................................................................
Step 4: Create fragement java class inside src folder .
TestFragmnet .java
...................................................................................................................................................................

package com.androidbeginner.testcode;

import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

public class TestFragmnet extends Fragment{
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View myFragmentView = inflater.inflate(R.layout.fragment_layout, container, false);
 
return myFragmentView;
}

}
.................................................................................................................................................................

try this code...




Read more

    

In this blog explain how to shared android app.

Step 1 first, add this code  in manifest file.



<activity android:name="com.oxample.tickmyad.ShareApp" >
            <intent-filter>
                <action android:name="android.intent.action.SEND" />

                <category android:name="android.intent.category.DEFAULT" />

                <data android:mimeType="text/plain" />
            </intent-filter>
        </activity>
   

manifest.xml
................................................................................................................................................................
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.androidtestcode"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="11"
        android:targetSdkVersion="21" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
         <activity android:name="com.example.tickmyad.ShareApp" >
            <intent-filter>
                <action android:name="android.intent.action.SEND" />

                <category android:name="android.intent.category.DEFAULT" />

                <data android:mimeType="text/plain" />
            </intent-filter>
        </activity>  
    </application>

</manifest>



activity_main.xml.
................................................................................................................................................................
<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: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.example.androidtestcode.MainActivity" >

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="150dp"
        android:text="share App" />

</RelativeLayout>



MainActivity.java.
................................................................................................................................................................
package com.example.androidtestcode;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class MainActivity extends  Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button btn=(Button)findViewById(R.id.button1);
btn.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent shareIntent = new Intent(Intent.ACTION_SEND);
// set  text type
shareIntent.setType("text/plain");
// set share url
shareIntent.putExtra(Intent.EXTRA_TEXT, "Click                                                                                                                                    On,http://androidbeginnerpoint.blogspot.in/");
startActivity(Intent.createChooser(shareIntent, "Share"));
}
});
}

}
...................................................................................................................................................................
try this code...











Read more

Water Ripple Animation in Android

In this blog implement water ripple animation .explain the code...

In this blog used some extra xml and java class.click here

Step 1. In this class you can set the RippleBackground class attrs accordingly.
activity_main.xml.
...................................................................................................................................................................

 <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:id="@+id/ScrollView1"
            android:background="#4b70dd"
             >

            <com.webnetware.view.RippleBackground
                xmlns:android="http://schemas.android.com/apk/res/android"
                xmlns:app="http://schemas.android.com/apk/res-auto"
                android:id="@+id/content"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_marginBottom="-4dip"
                app:rb_color="#a9d3ec"
                app:rb_duration="3000"
                app:rb_radius="64dp"
                app:rb_rippleAmount="7"
                app:rb_scale="14" >

                 

                <ImageView
                    android:id="@+id/imageView"
                    android:layout_width="50dp"
                    android:layout_height="50dp"
                    android:layout_alignParentEnd="true"
                    android:layout_alignParentRight="true"
                    android:layout_centerVertical="true"
                    android:contentDescription="@null"
                    android:src="@drawable/forword_arrow" />
            </com.webnetware.view.RippleBackground>
        </RelativeLayout>

...................................................................................................................................................................

MainActivity.java.
..................................................................................................................................................................

import java.util.ArrayList;

import android.animation.Animator;
import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.AccelerateDecelerateInterpolator;
import android.widget.ImageView;

import com.webnetware.singingbowl.R;
import com.webnetware.view.RippleBackground;

public class Splash_ScreenActivity extends Activity{
 RippleBackground rippleBackground;
 ImageView image;
private static int SPLASH_TIME_OUT = 3000;
@Override
protected void onCreate(Bundle savedInstanceState) {
 
super.onCreate(savedInstanceState);
setContentView(R.layout.term_and_activity);
rippleBackground=(RippleBackground)findViewById(R.id.content);
image = (ImageView) findViewById(R.id.imageView);
rippleBackground.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {

rippleBackground.startRippleAnimation();
foundDevice(image);
}
});
...................................................................................................................................................................

Open first Screen.


Start the animation ,when you click on layout.





Read more

Water Ripple effect onClick Layout in Android

In this blog explain how to show water effcte onclick layout in android. explain how

Step 1.Create attrs xml class in res/value/attrs.xml. In this class write a attr name as per rquire...
attrs.xml.
..................................................................................................................................................................
<?xml version="1.0" encoding="utf-8"?>
<resources>
    <declare-styleable name="RippleBackground">
        
        <attr name="rb_color" format="color" />
        <attr name="rb_strokeWidth" format="dimension"/>
        <attr name="rb_radius" format="dimension"/>
        <attr name="rb_duration" format="integer"/>
        <attr name="rb_rippleAmount" format="integer"/>
        <attr name="rb_scale" format="float"/>
        
        <attr name="rb_type" format="enum">
            <enum name="fillRipple" value="0"/>
            <enum name="strokeRipple" value="0"/>
        </attr>
        
    </declare-styleable>

   
    
</resources>
..................................................................................................................................................................

Step 2 Create dimentions xml class inside res/value/dimentions.xml. In this class add dimen ripple width or ripple radius accordingly. 
dimentions.xml
..................................................................................................................................................................

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <dimen name="rippleStrokeWidth">2dp</dimen>
    <dimen name="rippleRadius">64dp</dimen>
</resources>
..................................................................................................................................................................

Step 3.Create RippleBackground  xml  layout via programmatically.

 RippleBackground .java
.................................................................................................................................................................

import android.animation.Animator;
import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.view.View;
import android.view.animation.AccelerateDecelerateInterpolator;
import android.widget.RelativeLayout;

import java.util.ArrayList;

import com.webnetware.singingbowl.R;



public class RippleBackground extends RelativeLayout{

    private static final int DEFAULT_RIPPLE_COUNT=12;
    private static final int DEFAULT_DURATION_TIME=3000;
    private static final float DEFAULT_SCALE=12.0f;
    private static final int DEFAULT_FILL_TYPE=0;

    private int rippleColor;
    private float rippleStrokeWidth;
    private float rippleRadius;
    private int rippleDurationTime;
    private int rippleAmount;
    private int rippleDelay;
    private float rippleScale;
    private int rippleType;
    private Paint paint;
    private boolean animationRunning=false;
    private AnimatorSet animatorSet;
    private ArrayList<Animator> animatorList;
    private LayoutParams rippleParams;
 
    private ArrayList<RippleView> rippleViewList=new ArrayList<RippleView>();

    public RippleBackground(Context context) {
        super(context);
    }

    public RippleBackground(Context context, AttributeSet attrs) {
        super(context, attrs);
        init(context, attrs);
    }

    public RippleBackground(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init(context, attrs);
    }

    private void init(final Context context, final AttributeSet attrs) {
        if (isInEditMode())
            return;

        if (null == attrs) {
            throw new IllegalArgumentException("Attributes should be provided to this view,");
        }

        final TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.RippleBackground);
        rippleColor=typedArray.getColor(R.styleable.RippleBackground_rb_color, getResources().getColor(R.color.rippelColor));
        rippleStrokeWidth=typedArray.getDimension(R.styleable.RippleBackground_rb_strokeWidth, getResources().getDimension(R.dimen.rippleStrokeWidth));
        rippleRadius=typedArray.getDimension(R.styleable.RippleBackground_rb_radius,getResources().getDimension(R.dimen.rippleRadius));
        rippleDurationTime=typedArray.getInt(R.styleable.RippleBackground_rb_duration,DEFAULT_DURATION_TIME);
        rippleAmount=typedArray.getInt(R.styleable.RippleBackground_rb_rippleAmount,DEFAULT_RIPPLE_COUNT);
        rippleScale=typedArray.getFloat(R.styleable.RippleBackground_rb_scale,DEFAULT_SCALE);
        rippleType=typedArray.getInt(R.styleable.RippleBackground_rb_type,DEFAULT_FILL_TYPE);
     
        typedArray.recycle();

        rippleDelay=rippleDurationTime/rippleAmount;

        paint = new Paint();
        paint.setAntiAlias(true);
        if(rippleType==DEFAULT_FILL_TYPE){
            rippleStrokeWidth=0;
            paint.setStyle(Paint.Style.FILL);
        }else
            paint.setStyle(Paint.Style.STROKE);
        paint.setColor(rippleColor);

        rippleParams=new LayoutParams((int)(2*(rippleRadius+rippleStrokeWidth)),(int)(2*(rippleRadius+rippleStrokeWidth)));
        rippleParams.addRule(CENTER_IN_PARENT, TRUE);

        animatorSet = new AnimatorSet();
        animatorSet.setInterpolator(new AccelerateDecelerateInterpolator());
        animatorList=new ArrayList<Animator>();

            for(int i=0;i<rippleAmount;i++){
           
            RippleView rippleView=new RippleView(getContext());
            addView(rippleView,rippleParams);
            rippleViewList.add(rippleView);
         
            final ObjectAnimator scaleXAnimator = ObjectAnimator.ofFloat(rippleView, "ScaleX", 1.0f, rippleScale);
            scaleXAnimator.setRepeatCount(ObjectAnimator.INFINITE);
            scaleXAnimator.setRepeatMode(ObjectAnimator.RESTART);
            scaleXAnimator.setStartDelay(i * rippleDelay);
            scaleXAnimator.setDuration(rippleDurationTime);
            animatorList.add(scaleXAnimator);
         
            final ObjectAnimator scaleYAnimator = ObjectAnimator.ofFloat(rippleView, "ScaleY", 1.0f, rippleScale);
            scaleYAnimator.setRepeatCount(ObjectAnimator.INFINITE);
            scaleYAnimator.setRepeatMode(ObjectAnimator.RESTART);
            scaleYAnimator.setStartDelay(i * rippleDelay);
            scaleYAnimator.setDuration(rippleDurationTime);
            animatorList.add(scaleYAnimator);
         
            final ObjectAnimator alphaAnimator = ObjectAnimator.ofFloat(rippleView, "Alpha", 1.0f, 0f);
            alphaAnimator.setRepeatCount(ObjectAnimator.INFINITE);
            alphaAnimator.setRepeatMode(ObjectAnimator.RESTART);
            alphaAnimator.setStartDelay(i * rippleDelay);
            alphaAnimator.setDuration(rippleDurationTime);
            animatorList.add(alphaAnimator);
        }

        animatorSet.playTogether(animatorList);
    }

    private class RippleView extends View{

        public RippleView(Context context) {
            super(context);
            this.setVisibility(View.INVISIBLE);
        }

        @Override
        protected void onDraw(Canvas canvas) {
       
            int radius=(Math.min(getWidth(),getHeight()))/2;
            canvas.drawCircle(radius,radius,radius-rippleStrokeWidth,paint);
        }
    }

    public void startRippleAnimation(){
   
        if(!isRippleAnimationRunning()){
       
            for(RippleView rippleView:rippleViewList){
                rippleView.setVisibility(VISIBLE);
            }
         
            animatorSet.start();
            animationRunning=true;
        }
    }

    public void stopRippleAnimation(){
   
        if(isRippleAnimationRunning()){
            animatorSet.end();
            animationRunning=false;
        }
    }

    public boolean isRippleAnimationRunning(){
   
        return animationRunning;
    }
}
...................................................................................................................................................................

Step 4. Create activity_main inside res/layout folder.....

activity_main.xml
.................................................................................................................................................................

        <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:id="@+id/ScrollView1"
            android:background="@drawable/background"
             >

            <com.webnetware.view.RippleBackground
                xmlns:android="http://schemas.android.com/apk/res/android"
                xmlns:app="http://schemas.android.com/apk/res-auto"
                android:id="@+id/content"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_marginBottom="-4dip"
                app:rb_color="@color/one_backcolor"
                app:rb_duration="3000"
                app:rb_radius="32dp"
                app:rb_rippleAmount="1"
                app:rb_scale="14" >

                 

                <ImageView
                    android:id="@+id/imageView"
                    android:layout_width="50dp"
                    android:layout_height="50dp"
                    android:layout_alignParentEnd="true"
                    android:layout_alignParentRight="true"
                    android:layout_centerVertical="true"
                    android:contentDescription="@null"
                    android:src="@drawable/forword_arrow" />
            </com.webnetware.view.RippleBackground>
        </RelativeLayout>
...................................................................................................................................................................
        
    
Step 5. create MainActivity java class inside src/ folder
        
    MainActivity.xml
..................................................................................................................................................................


import java.util.ArrayList;

import android.animation.Animator;
import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.AccelerateDecelerateInterpolator;
import android.widget.ImageView;

import com.webnetware.singingbowl.R;
import com.webnetware.view.RippleBackground;

public class Splash_ScreenActivity extends Activity{
RippleBackground rippleBackground;
ImageView image;
private static int SPLASH_TIME_OUT = 3000;
@Override
protected void onCreate(Bundle savedInstanceState) {
 
super.onCreate(savedInstanceState);
setContentView(R.layout.term_and_activity);
rippleBackground=(RippleBackground)findViewById(R.id.content);
image = (ImageView) findViewById(R.id.imageView);
rippleBackground.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
rippleBackground.startRippleAnimation();
foundDevice(image);
  new Handler().postDelayed(new Runnable() {
   
    @Override
    public void run() {  
    rippleBackground.stopRippleAnimation();;  
     
        }  
         }, 3000);  
}
});
..................................................................................................................................................................

first screen without onClick.


second,when we are click on layout.


Read more