Android, make a rather complicated animation? - android

I know how to make a typical animation using Animation API in Android. But I don't know how to make this:
It is simply a textview inside a ring while the ring is animating and the textview is just in a fix state. Note that the ring thickness is not changing while scaling.

Assuming you have your ring as a view already, you simply create an AnimatorSet with two ObjectAnimators that changes the scaleX and scaleY of the ring view. How far to scale depends on how far you want the ring to extend out or in.
Make sure you set the pivotX and pivotY to be the center of the view.
Then, simply have it repeat.

Related

When does Android set a view's pivotX and pivotY values?

I have an ImageView which is sometimes, but not always, being positioned incorrectly. It appears that sometimes it gets displayed before its pivotX and pivotY values are set. So they are both zero and the ImageView appears in the upper left hand corner of its space. And once drawn, both pivotX and pivotY never get set for that View and it remains out of place. I can "fix" it by explicitly setting pivotX and pivotY in the XML. But that is a hack. Better to determine root cause and find out when pivotX and pivotY should be set to understand why they aren't. Clearly it is a multi-threading issue and something is (somehow) drawing the image before it is properly initialized. So when do these values get set and/or what can cause them to not be set?

Animate activity exit transition with pivot- alternative to overridePendingTransition()

First of all not duplicate of : Alternative to overridePendingTransition() - Android
I want to scale an activity (exit) with a pivot point. The problem is that the xml pivotX & pivotY values use pixels which makes things difficult. So overridePendingTransition() is not really helpful because it only uses a xml animation.
So I want to animate the scale-exit of an activity (from 1f to 0f scaling rate) with a pivot of 50dp of the right of the screen and 100dp from the bottom of the screen.
Any ideas?
You have to start a transparent Activity and make your animation from here
Look at Android Developers Activity Animation where they explain the old custom/manual Activity Transition.

android, how to sweep alpha animation from left to right?

I should display an animation that draws line from left to right. Please look at following image.
First layer is background (whole image without root lines and country names)
Second layer is lines and country names.
I can use alpha animation in following way in my activity:
mIvRoot = (ImageView) findViewById(R.id.ivRoot);
ObjectAnimator alphaAnim = ObjectAnimator.ofFloat(mIvRoot, "alpha", 0f, 1f);
alphaAnim.setDuration(2000);
alphaAnim.start();
Although it works fine, however alpha applies to whole image. The thing that I'm looking for instead is alpha applies from left to right. Therefore, user feels lines are drawing.
Any suggestion would be appreciated. Thanks
I fixed temporarily my problem in a bl.sht way. Please share with me your idea to fix this way.
I placed another white view (since my background is white) on top of root image and assigned it translation animation instead of using alpha animation Like this:
<View
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#color/White"
android:id="#+id/viCover"
android:layout_alignTop="#+id/ivRoot"
android:layout_alignBottom="#+id/ivRoot"
android:layout_alignLeft="#+id/ivRoot"
android:layout_alignRight="#+id/ivRoot"
android:layout_marginLeft="200dp"/>
and code:
ObjectAnimator transRootAnim = ObjectAnimator.ofFloat(mViCover, "translationX", 0f, 1500f);
transRootAnim.setDuration(3000);
transRootAnim.start();
Even though i didn't understand why you're not actually drawing those lines, you may want to look at this post by Romain Guy that he also made something similar (Actually almost same :))

Dynamically changing the border of View

I am just planning to implement a view whose border color keeps on changing dynamically at run time based on a timer. For example initially the view's border will be in green color(timer=20sec) and every sec the green color disappears and once it goes of more than half(timer=10sec) of the view... the border color should change to orange and once it reaches the end(timer=5sec) of timer it should be in red color and phone should vibrate (easy can be done).... If somebody is familiar with zynga poker its the same that i want to implement.
Now one way of implementing it could be have a backend timer and based on that have "n" number of drawables and keep on changing the background of the view every sec. But this requires many images and i dont think this is the optimal way of implementing it.
just wondering if i can write a custom view and implement the surface view and do something around it so that this can be done. Anybody has any idea on how to achieve this? can this be done using any animations around customviews? Any ideas around this are greatly appreciated.
Thanks in advance
Run a timertask, and change the border of the view by setting the background value of the view to a style.
Like,
view.setBackground(R.drawable.border_style_green);
So in the timer task, keep checking the time, and change the border.
Note - border_style_green is a XML file which has the style where you can set the border, the rounded corner to a view, etc.
My suggestion is to make use of the animation framework from android. If your app targets versions below honeycomb use NineOldAndroids.
As already suggested set the border by assigning shapeDrawable to your view
view.setBackground(R.drawable.border_style_green);
you start the animator like this. (this code will animate from currentColor to red in 1000ms)
ObjectAnimator animator = ObjectAnimator.ofFloat(this, "color", currentColor,Color.RED);
animator.setEvaluator(new ArgbEvaluator());
animator.setDuration(1000);
animator.start();
Then in your activity implement:
public void setColor(int color){
currentColor = color;
view.getBackground().setColorFilter(color, PorterDuff.Mode.MULTIPLY);
}
if view is html page : Use Jquery for this implementation. by ajax you can call backend as well. Jquery delay function

How to force android view to redraw it's background-drawable? / probably an animation is blocking it to work properly

Is there a way to force an android view to redraw it's background?
I have set a drawable shape with a gradient as background which works fine but after changing the view's height you can see those ugly gradient steps.
What can I do?
I tried view.invalidate() and view.refreshDrawableState() without any visible difference.
Thank you!
//EDIT:
Here are some more details and my code:
After your answers I think the banding is a result of my probably bad code. Here is what I'm doing:
Scaling a view
setting its new width and height because the scaled view does not accept user input in other areas then the "old" one (see android weird (at least for me) behaviour of control after scaling / doesn't accept input in it's whole area )
trying to set the background again (which contains a gradient and a rectangle with rounded corners)
Here is my code:
public void onAnimationEnd(Animation animation)
{
MyView view = (MyView) ((ExtendedScaleAnimation) animation).getView();
view.getLayoutParams().width = toWidth;
view.getLayoutParams().height = toHeight;
view.clearAnimation();
view.requestLayout();
view.refreshBackground(); // background will be changed
}
On the device you can see that the background drawable is changed but there is a flickering which seems to me like the backround change is applied before the animation is over. Programatically it should be over! Or am I wrong?
Thank you again!
Can you try after resize:
v.setBackgroundResource(null);
v.setBackgroundResource(...my drawable...);

Categories

Resources