Ie to the edges are not round, and sharp under 90 gr.
1 answer
Create a square ImageView in the markup:
<ImageView android:id="@+id/image" android:layout_width="200dp" android:layout_height="200dp" android:layout_gravity="center" android:background="@drawable/rectangle" /> Its rectangle.xml background is in the drawable folder:
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android"> <solid android:color="#f00"/> <corners android:radius="100dp" /> </shape> Here it is important that the radius of the corners be half the width of the ImageView . Then get a circle.
Next in the activation by pressing the button we start the animation, gradually reducing the radius of the rectangle's corners (from 100 to 0):
fab.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { final GradientDrawable shape = new GradientDrawable(); shape.setColor(Color.RED); final ImageView imageView = (ImageView) findViewById(R.id.image); ValueAnimator anim = ValueAnimator.ofInt(100, 0); anim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { shape.setCornerRadius((int)animation.getAnimatedValue()); imageView.setImageDrawable(shape); } }); anim.setDuration(5000); anim.start(); } }); Powered by API starting at 11.
|