I want to achieve animation when I send my message it goes from bottom to top like flying a bird (though I have done it :P) but while flying, that chat bubble view's radius is also changing(This is the thing I am not able to achieve).
Please help me to achieve this kind of animation or give me some sort of hint.
Thank you
I have used below code to set radius and then translate that view using xml file but not able to change radius on the go.
GradientDrawable gd = new GradientDrawable();
// Specify the shape of drawable
gd.setShape(GradientDrawable.RECTANGLE);
// Set the fill color of drawable
gd.setColor(Color.TRANSPARENT); // make the background transparent
// Create a 2 pixels width red colored border for drawable
gd.setStroke(2, Color.RED); // border width and color
// Make the border rounded
gd.setCornerRadius(15.0f);
((RelativeLayout) findViewById(R.id.rlvView)).setBackground(gd);
Animation animation = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.item_animation_from_bottom);
((RelativeLayout) findViewById(R.id.rlvView)).startAnimation(animation);
You need to use ObjectAnimator (derivative class of ValueAnimator) to achieve animate any value (visible/invisible) of a view. Code below animate cornerRadius for one time from 15.0f to 0. Please try, I hope it helps.
// Make the border rounded
gd.setCornerRadius(15.0f);
((RelativeLayout) findViewById(R.id.rlvView)).setBackground(gd);
ObjectAnimator animator = ObjectAnimator.ofFloat(gd, "cornerRadius", 0);
animator.setInterpolator(new LinearInterpolator());
animator.setDuration(800);
animator.start();
Related
I'm trying to use a very simple code to fade the background color change in a textview
the idea is to chose a new color, than have it fade from transparent to the desired color, here is the code:
ValueAnimator anim = new ValueAnimator();
anim.setEvaluator(ArgbEvaluator.getInstance());
anim.setDuration(1500);
anim.setIntValues(hightlightColor & 0x00FFFFFF, hightlightColor);
// txtView.setBackgroundColor(hightlightColor);
anim.addUpdateListener(animation -> txtView.setBackgroundColor((int) animation.getAnimatedValue()));
anim.start();
highlight color is just a green i'm using for example, txtview is a valid textview and the current background is null
but instead of creating a fade in shades of green the code results in a crazy rainbow like interpolation, that ends exactly in the desired green, but all intermediate values are shit
I thought it might be the alpha channel so i tested starting from white to green but the intermediate colors were all crazy also
MY APP MINSDK IS 16 SO I CANT USE ValueAnimator.ofArgb()
here is how it looks
Like the title said, I'm looking a easy way to customize the color used in reveal.
I want to use official code if it's possible (avoiding 3rd party libraries).
I'm using the usual code:
Animator anim = ViewAnimationUtils.createCircularReveal(myView, cx, cy, 0, finalRadius);
myView.setVisibility(View.VISIBLE);
anim.start();
The circular reveal animation doesn't have any color. If you want color, you need to set the background color on the view you are providing to circular reveal.
I'm trying to achieve an animation which scales over a view like this:
At the moment I'm using a scale animation loaded from xml:
This in action looks like this:
It scales more like a square.
I was using ObjectAnimator/ValueAnimator with properties before.
Some devices had specific problems with measuring heights for scaling so I reverted to using xml definitions.
Does anyone have any clue how to achieve the above?
you must define programmatically you ScaleAnimation.
first get radius of your circle(ImageView) at first position(before start Animation).
for get radius you can get width of your imageview and then division to 2.
second you must get width and height of your square.
third do it :
anim_to = (width_square + height_Square) / radius_circle;
finally set "anim_to" to your ScaleAnimation and start animation like this:
ScaleAnimation my_reveal = new ScaleAnimation(1,anim_to, 1,anim_to, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
my_reveal.setInterpolator(new DecelerateInterpolator());
my_reveal.setDuration(500);
my_circle.startAnimation(my_reveal);
sorry for my bad ENG ;)
EDIT: LOOK AT SOLUTION ABOVE
i m freaking out. all i just want to do, is setting a linear GradientDrawable, which changes the vertical center of the gradient... drawing the gradient works fine, but how can i change the center of it?!?
RelativeLayout bgScreen = (RelativeLayout) findViewById(R.id.player_screen);
GradientDrawable gd = new GradientDrawable(
GradientDrawable.Orientation.TOP_BOTTOM,
new int[] {startColor,endColor});
gd.setCornerRadius(0f);
gd.setAlpha(200);
bgScreen.setBackground(gd);
public void redrawOrChangeBackgroundGradient(){
//??? either change center of existing
gd.setGradientCenter(float x, float y) //ONLY works in RADIAL_GRADIENT or SWEEP_GRADIENT.
//??? or complete redraw Gradient with different center
}
here s a picture example of how i want to change the gradient via code
cannot be that hard, can it?
The lacking ability to set the center programmatically for linear GradientDrawables is a registered issue already.
But there is a workaround described here. Basically, you should create a PaintDrawable from a LinearGradient and set it as your view's background drawable. Following this solution, you can set the center in your LinearGradient constructor by mapping the colors to the positions array:
float[] positions
May be null. The relative positions [0..1] of each corresponding color
in the colors array. If this is null, the colors are distributed
evenly along the gradient line.
(not tested, but it should do the trick for you)
Alphaing a drawable work well like this:
if(mAlphaAnimation == null){
mAlphaAnimation = ObjectAnimator.ofFloat(this, "alpha", 0.0f,1.0f).setDuration(TARGET_ANIM_ALPHA_DURATION);
mAlphaAnimation.setInterpolator(new AccelerateDecelerateInterpolator());
mAlphaAnimation.setStartDelay(TARGET_ANIM_ALPHA_DELAY_BASE*power);
mAlphaAnimation.setRepeatCount(ValueAnimator.INFINITE);
mAlphaAnimation.setRepeatMode(ValueAnimator.REVERSE);
mAlphaAnimation.addUpdateListener(this);
}
But if I want rotate a drawable like below , it don's work.
private void createRotateAnim(float fromDegress,float toDegress,int duration){
if(mRotateAnimation == null){
mRotateAnimation = ObjectAnimator.ofFloat(this, "rotation",fromDegress,toDegress).setDuration(duration);
mRotateAnimation.setStartDelay(100);
mRotateAnimation.setInterpolator(new AccelerateInterpolator());
mRotateAnimation.addUpdateListener(this);
}
}
Anyone can help me to fix this issue, or these is any other way to create a rotation drawable animation .
I am sorry to my poor English.
Try with ObjectAnimator instead.
ImageView imageview = (ImageView)findViewById(R.id.image);
ObjectAnimator imageViewObjectAnimator = ObjectAnimator.ofFloat(imageview ,
"rotation", 0f, 360f);
imageViewObjectAnimator.setDuration(1000); // miliseconds
imageViewObjectAnimator.start();
EDIT
Since this question draw some attention let me to explain why to use ObjectAnimator instead of other Transition animators
The thing about using ObjectAnimator is that it's moving both the visible and the clickable area of the item, if you use another animation method, for example Transition Animation or some other Animators, and let's say if you want to move the Button from the bottom left of the screen to the top left, it will only move the visible area but not the Button itself, the clickable area will still be on the previous position, in this case the clickable area will still be on the bottom left instead of the top left where you moved the button.
If you do the same with ObjectAnimator, both the visible area, and the clickable area will move the the desired location.
Try this simple Rotation Animation applied to a image.
ImageView imageview = (ImageView)findViewById(R.id.myimage);
RotateAnimation rotate = new RotateAnimation(180, 360, Animation.RELATIVE_TO_SELF,
0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
rotate.setDuration(500);
imageview.startAnimation(rotate);
This answer is just for a sake of question, it is correct that Clickable area will be different than View's current position. Please check this question for making clickable area correct. Button is not clickable after TranslateAnimation