MPAndroidChart PieChart Animations - android

I set 2 values on piechart. I want to animate it. But I want to change animation way. All animations do right to left angle. I want to do left to right angle. How can I change animation direction?
Edit 1: Library: MPAndroidChart
Edit 2: Althought it is not very relevant, I add following code here.
mButton_AvailableLimit.setOnClickListener( new View.OnClickListener() {
#Override
public void onClick(View v) {
// fromAngle and toAngle is a float variables that less then 360
mPieChart.spin( 500,fromAngle,360 - toAngle, Easing.EasingOption.EaseInOutQuad );
}
} );

It's very simple in fact,
//for rotating anti-clockwise
mPieChart.spin( 500,0,-360f, Easing.EasingOption.EaseInOutQuad);

pieChart.animateX(1000); this is work fine

Related

How To Change pivot and set to Center in yoyo lib Animation

I have a problem with yoyo lib. when I run the project, Animation Rotate from top-left corner. I want change .pivot() and set to center pivot.
in fact I want Animation Rotation on the center pivot, as like Rotation Ball.
But I don't know how to change code.
Thanks for help.
My Code:
YoYo.with(Techniques.RotateIn)
.duration(2000)
.pivot(float pivotX, float pivotY) //How to set parameters this line code?
.playOn(my_view);
The default pivot is:
.pivot(YoYo.CENTER_PIVOT, YoYo.CENTER_PIVOT)
You can add a GlobalLayoutListener if your view is not loaded completely:
yourView.getViewTreeObserver().addOnGlobalLayoutListener (new ViewTreeObserver.OnGlobalLayoutListener() {
#Override
public void onGlobalLayout() {
YoYo.with(Techniques.RotateIn)
.duration(2000)
.pivot(YoYo.CENTER_PIVOT, YoYo.CENTER_PIVOT)
.playOn(yourView);
}
});

ImageView rotates only once using AccelerateDecelerateInterpolator

I am trying to rotate an image by 360 degree using AccelerateDecelerateInterpolator. I have included the code to rotate the image in an onclickfunction of a button. When i press the button for the first time, the image rotates. However, when i press it the next time, nothing happens.
public void displaySpinResult_Spinner(View view) {
arrow.animate().rotation(360).setInterpolator(new AccelerateDecelerateInterpolator()).start();
}
This is probably because the rotation value is retained. When you specify rotation(360) for the second time, the View is already rotated by 360degrees, so nothing happens.
You can either try rotation(arrow.getRotation() + 360), or use the rotationBy() method instead.
I think this is the solution:
public void displaySpinResult_Spinner(View view) {
arrow.animate().rotation(360).setInterpolator(new AccelerateDecelerateInterpolator()).start();
arrow.animate().rotation(360).setInterpolator(new AccelerateDecelerateInterpolator()).reset();
}

Move ImageView with animation

I'm trying to move an ImageView with this code:
img.animate().translationY(110).setDuration(1500);
But if I try to move it again later with something like:
img.animate().translationY(-110).setDuration(1500);
The ImageView moves from where it used to be before I moved it in the first place.
What I would expect is for it to return to it's original position. What am I missing here?
Try this
img.animate().translationY(0).setDuration(1500);
you should use animationSet and also -
animationSet.setFillAfter(true);
Good luck.
Maybe you could just get the translation and add it?
public void ClickMoveDown{
float distance = 100;
Move (0,distance)
}
private void Move (float x, float y){
img.animate().translationX(img.getTranslationX+x).setDuration(1500);
img.animate().translationY(img.getTranslationY+y).setDuration(1500);
}
you have to move it after (in your case) 1.5 seconds is passed
float originalPosition = img.getY();
img.animate().translationY(110).setDuration(1500).start();
img.animate().translationY(originalPosition).setStartDelay(1500).setDuration(1500).start();
im not so sure about the method names..
TranslateAnimation animationDown = new TranslateAnimation(00.0f, 00.0f, 00.0f, 500);
animationDown.setDuration(800);
animationDown.setRepeatMode(android.view.animation.Animation.REVERSE);
animationDown.setRepeatCount(android.view.animation.Animation.INFINITE);
This will make the image move straight down then reverse its track back up to its original spot maintaining speed. Also take note you can make multiple of these and add them to one animation set to get the desired square pattern i believe how you would store it into a set is as such...
AnimationSet example = new AnimationSet(true);
example.addAnimation(animationDown);
"" and so on until
s.setStartTime();
or
s.startAnimationSet();

Can I partially hide a layout?

As I've a master in MS Paint, I will just upload a picture selfdescripting what I'm trying to achieve.
I've searched, but I'm not really sure what do I've to search. I've found something called Animations. I managed to rotate, fade, etc an element from a View (with this great tutorial http://www.vogella.com/articles/AndroidAnimation/article.html)
But this is a bit limited for what I'm trying to achieve, and now, I'm stuck, because I don't know how is this really called in android development. Tried words like "scrollup layouts" but I didn't get any better results.
Can you give me some tips?
Thank you.
You can see a live example, with this app: https://play.google.com/store/apps/details?id=alexcrusher.just6weeks
Sincerely,
Sergi
Use something like this as your layout (Use Linear, Relative or other layout if you wish):
<LinearLayout
android:id="#+id/lty_parent">
<LinearLayout
android:id="#+id/lyt_first" />
<LinearLayout
android:id="#+id/lyt_second"/>
</LinearLayout>
And then in an onClick method on whatever you want to use to control it, set the Visibility between Visible and Gone.
public void buttonClickListener(){
((Button) findViewById(R.id.your_button))
.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
if (lyt_second.getVisibility() == View.GONE) {
lyt_second.setVisibility(View.VISIBILE);
}
else {
lyt_second.setVisibility(View.GONE);
}
});
Which is fine if you just want a simple appear/disappear with nothing fancy. Things get a little bit more complicated if you want to animate it, as you need to play around with negative margins in order to make it appear to grow and shrink, like so:
We use the same onClick method that we did before, but this time when we click it starts up a custom SlideAnimation for the hidden/visible view.
#Override
public void onClick(View v) {
SlideAnimation slideAnim = new SlideAnimation(lyt_second, time);
lyt_second.startAnimation(slideAnim);
}
The implementation of the SlideAnimation is based on a general Animation class, which we extend and then Override the transformation.
public SlideAnimation(View view, int duration) {
//Set the duration of the animation to the int we passed in
setDuration(duration);
//Set the view to be animated to the view we passed in
viewToBeAnimated = view;
//Get the Margin Parameters for the view so we can edit them
viewMarginParams = (MarginLayoutParams) view.getLayoutParams();
//If the view is VISIBLE, hide it after. If it's GONE, show it before we start.
hideAfter = (view.getVisibility() == View.VISIBLE);
//First off, start the margin at the bottom margin we've already set.
//You need your layout to have a negative margin for this to work correctly.
marginStart = viewMarginParams.bottomMargin;
//Decide if we're expanding or collapsing
if (marginStart == 0){
marginEnd = 0 - view.getHeight();
}
else {
marginEnd = 0;
}
//Make sure the view is visible for our animation
view.setVisibility(View.VISIBLE);
}
#Override
protected void applyTransformation(float interpolatedTime, Transformation t) {
super.applyTransformation(interpolatedTime, t);
if (interpolatedTime < 1.0f) {
// Setting the new bottom margin to the start of the margin
// plus the inbetween bits
viewMarginParams.bottomMargin = marginStart
+ (int) ((marginEnd - marginStart) * interpolatedTime);
// Request the layout as it happens so we can see it redrawing
viewToBeAnimated.requestLayout();
// Make sure we have finished before we mess about with the rest of it
} else if (!alreadyFinished) {
viewMarginParams.bottomMargin = marginEnd;
viewToBeAnimated.requestLayout();
if (hideAfter) {
viewToBeAnimated.setVisibility(View.GONE);
}
alreadyFinished = true;
}
hideAfter = false;
}
}
EDIT: If anyone had used this code before and found that if you click on the button that starts the animation more than once before the animation was finished, it would mess up the animation from then on, causing it to always hide the view after the animation finished. I missed the reset of the hideAfter boolean near the bottom of the code, added it now.
you can do this manually by using setvisibility feature on the event onClick()
or
use this
dynamically adding two views one below other

Buttons on an animated view respond to clicks even when off screen?

I have a LinearLayout, I'm applying a translation animation to it. I'm filling the animation before and after. Visually it works fine. The animation ends by translating the view off screen. But if I click an x,y coordinate on screen that happens to be where the view was at some point during its animation, a button on the view has its click listener fire.
The only solution I've found is to add an animation listener, and when the animation ends, mark the buttons on the (now out of view) layout to visibility=gone, enabled=false. This seems bizarre - the view is no longer on screen, but it's still responding to click events. Is this a known thing, I'm probably not setting the animation up correctly?
Thanks
----- Update --------
I refactored my animation a little. Instead of using animation.setFillAfter(true), I set the layout's visibility to GONE when the animation is complete. Now it doesn't register clicks when off-screen. Still interested to know if this is a known thing, as it'd be easier to simply not have to add an animation listener etc.
Translate Animations on lower level API( below honey comb) changes where the button is drawn, but not where the button physically exists within the container. So, you are on your own to handle this situation. For more information about this you can refer to this link. One way is to actually change the location of the button in the layout(not by animation). Here is how you can achieve this:
params = (LayoutParams) mBtn.getLayoutParams();
TranslateAnimation animation = new TranslateAnimation(0, 0, 0, 400);
animation.setDuration(2000);
animation.setAnimationListener(mAnimationListener);
mBtn.startAnimation(animation);
....
....
private AnimationListener mAnimationListener = new AnimationListener() {
#Override
public void onAnimationStart(Animation animation) {
}
#Override
public void onAnimationRepeat(Animation animation) {
}
#Override
public void onAnimationEnd(Animation animation) {
params.topMargin = params.topMargin + 400;
mButton.setLayoutParams(params);
}
};
Here by changing the layout params we are changing the physical position of the button.
In your case as view is going off the screen so you just need to change the visibility of the button(View.GONE) on animation end.

Categories

Resources