android - How to set rounded corner on ImageView while using Animation on it


Keywords:android 


Question: 

I have a layout with some ImageView like this:enter image description here

As mention in the imageView corner's not remains rounded when used Animation on it.

How to make it rounded while using Animation on it?

Layout Code:

    <TableLayout
        android:layout_width="wrap_content"
        android:id="@+id/table1"
        android:gravity="center"
        android:layout_height="wrap_content">

    <TableRow>

    <ImageView
        android:layout_width="60dp"
        android:layout_height="60dp"
        android:id="@+id/img1_1"
        android:background="@drawable/button"
        android:layout_margin="3dp"
        />

    <ImageView
        android:layout_width="60dp"
        android:layout_height="60dp"
        android:id="@+id/img1_2"
        android:background="@drawable/button"
        android:layout_margin="3dp"
        />
    </TableRow>
    <TableRow>

    <ImageView
        android:layout_width="60dp"
        android:layout_height="60dp"
        android:id="@+id/img1_3"
        android:background="@drawable/button"
        android:layout_margin="3dp"
   />

    <ImageView
        android:layout_width="60dp"
        android:layout_height="60dp"
        android:id="@+id/img1_4"
        android:background="@drawable/button"
        android:layout_margin="3dp"
       />
    </TableRow>
</TableLayout>

Java Code:

  ObjectAnimator animator = ObjectAnimator.ofInt(findViewById(id), "backgroundColor", Color.RED, Color.parseColor("#4caf41")).setDuration(5000);
        Toast.makeText(Game.this, "index" + findViewById(id), Toast.LENGTH_LONG).show();
        animator.setEvaluator(new ArgbEvaluator());
        animator.start();   

3 Answers: 

When animation starts you are pressing the Imageview. So you can use

<selector xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:drawable="@drawable/numpad_button_bg_selected" android:state_selected="true"></item>
    <item android:drawable="@drawable/numpad_button_bg_pressed" android:state_pressed="true"></item>
    <item android:drawable="@drawable/numpad_button_bg_normal"></item>

</selector> 

use same image after button pressed.. May be it will help you..

 

You can use glide. It allows you to add animation as well.

 

I have resolve this issue to made chage in this line:

  ObjectAnimator animator = ObjectAnimator.ofInt(findViewById(id), "backgroundColor", Color.RED, Color.parseColor("#4caf41")).setDuration(5000);

like this:

  ObjectAnimator animator = ObjectAnimator.ofInt(findViewById(id), "backgroundResource", R.drawable.original_img, R.drawable.org_state).setDuration(2000);

i.e

I have set backgroundResource instead of backgroundColor.and set a image instead of hexcolor code.