I'm using the KenBurnsView library in here
But transition is not smooth and I don't know how to use the following code noted on github:
RandomTransitionGenerator generator = new RandomTransitionGenerator(duration, interpolator);
kbv.setTransitionGenerator(generator);
Can anyone help me how to create a smooth transition?
So you already have a KenBurnsView type object i.e kvb. To add a custom transition as the docs says and you also suggest.
Make
RandomTransitionGenerator generator = new RandomTransitionGenerator(duration, interpolator);
RandomTransitionGenerator is a class already included in the lib.
It takes 2 parameters :
1) duration i.e in miliseconds (usualy that the case)
2) interpolator - it is more like the effect of animation or rate of change of an animation.
We need to make an object of type Interpolator and use it like :
AccelerateDecelerateInterpolator ACCELERATE_DECELERATE = new AccelerateDecelerateInterpolator();
RandomTransitionGenerator generator = new RandomTransitionGenerator(10000, ACCELERATE_DECELERATE);
//duration = 10000ms = 10s and interpolator = ACCELERATE_DECELERATE
kbv.setTransitionGenerator(generator); //set new transition on kbv
the docs also adds that if you need more customization you can make your own TransitionGenerator class like RandomTransitionGenerator
Related
I am trying to add a sequence action. The problem is that only the first added action taken effect. For example in below code if i add mta first, I can only see mta action (the second action doesn't work). If I reverse then I see only the mtabite take effect.
Please help
MoveToAction mta = new MoveToAction();
mta.setPosition(x, y);
mta.setDuration(4f);
MoveToAction mtaBite = new MoveToAction();
mtaBite.setPosition(xFinal, yFinal);
mtaBite.setDuration(4f);
SequenceAction sequence = new SequenceAction();
sequence.addAction(mta);
sequence.addAction(mtaBite);
this.addAction(sequence);
Try something like this instead see if it works better:
actor.addAction(Actions.sequence(mta, mtaBite));
Also make sure your Actions are setup correctly.
mta.reset();
mta.setTime(0);
mta.setPosition(x, y);
mta.setInterpolation(Interpolation.fade);
mta.setDuration(4f);
It is best to use Tween Engine in order to animate in he libgdx.
Tween.to(myobject, Type.POSITION, 1.0f)
.targetRelative(10, -20) // the target can be relative to the current values
.delay(2.5f) // a delay can be specified
.ease(Quad.OUT) // the easing function can be modified
.repeat(2, 0.5f) // repetitions are possible
.repeatYoyo(2, 0.5f) // yoyo repetitions too (one play forward, the other backward, etc)
.setUserData(obj) // custom objects can be attached
.setCallback(cb) // callbacks can be specified to get notified of the completion
.setCallbackTriggers(...) // callbacks can be launched on many events, not just completion
.start(myManager);
http://www.aurelienribon.com/blog/projects/universal-tween-engine/
I want to merge animations in android application.
I'm using below code for that,but alpha animation not wrking.
I have no idea why it is not working.
// create set of animations
AnimationSet login_page_animation = new AnimationSet(false);
// animations should be applied on the finish line
login_page_animation.setFillAfter(true);
// create scale animation
int white_background_height=((TextView) findViewById(R.id.login_white_backgroud)).getHeight();
TranslateAnimation translate_animation = new TranslateAnimation(0,0,0,- white_background_height/4);
translate_animation.setDuration(700);
// create Alpha animation
AlphaAnimation alpha_animation=new AlphaAnimation(0.0f,1.0f);
alpha_animation.setDuration(700);
// add new animations to the set
login_page_animation.addAnimation(translate_animation);
login_page_animation.addAnimation(translate_animation);
Looks like you're adding translate_animation again on that last line instad of alpha_animation.
In my app , i want to use overshootInterpolator[android.R.anim.overshoot_interpolator].
Now ive created my custom overshootInterpolar in which ive set my own overshoot value.
But by default in overshootInterpolar the effect is like follows
Its accelerates right on start and slows down and then overshoots and come back.
What i want is it should not accelerate right on start.
So this is what i have tried
without success
<?xml version="1.0" encoding="utf-8"?>
<overshootInterpolator xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="#anim/hdr_accelerate_interpolar"
android:tension="1.3" />
Attribute: android:tension
Description: The amount of tension, the default is 2.
A larger tension will make the overshoot smaller and quicker.
#anim/hdr_accelerate_interpolar
<?xml version="1.0" encoding="utf-8"?>
<accelerateInterpolator xmlns:android="http://schemas.android.com/apk/res/android"
android:factor="2" />
Attribute: android:factor
Description: A larger value causes a slower initial motion and a
faster acceleration towards the end.
MY ISSUE: The accelerate interpolar is not taking effect.
You are trying to combine two interpolators into one by specifying an android:interpolator attribute within an interpolator resource. Unfortunately, this is not possible using XML resources and you will have to write your custom interpolator as a Java class and also set the interpolator on you animation programmatically.
As an example, your interpolator could look like this.
public class AccelerateOvershootInterpolator implements Interpolator
{
private AccelerateInterpolator accelerate;
private OvershootInterpolator overshoot;
public AccelerateOvershootInterpolator(float factor, float tension)
{
accelerate = new AccelerateInterpolator(factor);
overshoot = new OvershootInterpolator(tension);
}
#Override
public float getInterpolation(float input)
{
return overshoot.getInterpolation(accelerate.getInterpolation(input));
}
}
Of course you don't need to use the AccelerateInterpolator or the OvershootInterpolator. The getInterpolation method can apply any mathematical function to the input. To use this interpolator for an animation you need to create an instance of the interpolator and set it on your animation, like this.
Animation animation = AnimationUtils.loadAnimation(this, R.anim.my_animation);
AccelerateOvershootInterpolator interpolator = new AccelerateOvershootInterpolator(2.0f, 1.7f);
animation.setInterpolator(interpolator);
animatedView.startAnimation(animation);
For an overview on interpolators and how to implement your own, you can look at this tutorial http://cogitolearning.co.uk/?p=1078
I have a set of 10 images, and I want to create an animation where I cross fade between them. I've been looking into built-in Drawable to achieve such a thing, but no luck on that part.
There is the AnimationDrawable, that switch between pictures, but it doesn't animate the switch.
There is the TransitionDrawable, that cross fade between two pictures, but no more than two.
Hell.
I looked for some solution on Google, but no luck on that part. So I'm thinking about implementing my own drawable to achieve such a thing. Would any of you have any pointers ?
Thanks in advance.
Not sure if you found an answer to this, but I had the same problem and ended up building my own class based on TransitionDrawable.
Usage:
CyclicTransitionDrawable ctd = new CyclicTransitionDrawable(new Drawable[] {
drawable1,
drawable2,
drawable3,
...
});
imageView.setImageDrawable(ctd);
ctd.startTransition(1000, 3000) // 1 second transition, 3 second pause between transitions.
The code for the CyclicTransitionDrawable is available on Github.
Well. Long time has passed, and you probably fixed the issue, but you got setEnterFaceDuration() for AnimationDrawable. Example:
mBackgroundAnimation = new AnimationDrawable();
mBackgroundAnimation.addFrame(getResources().getDrawable(R.drawable.background1), 5000);
// ... rest of the frames
mBackgroundAnimation.addFrame(getResources().getDrawable(R.drawable.background6), 5000);
mBackgroundAnimation.setEnterFadeDuration(1000);
mBackgroundAnimation.setOneShot(false);
With this code you have an easy cycling through 1..N images, each one remains 5s (5000ms) with a fade-in animation. Now, what i do is setting the background of my root RelativeLayout
mLayoutRoot.setBackground(mBackgroundAnimation);
mLayoutRoot.post(new AnimationStarterThread());
And the AnimationStarterThread class
private class AnimationStarterThread implements Runnable {
public void run() {
if(mBackgroundAnimation != null)
mBackgroundAnimation.start();
}
}
In a similar approach to this question, I am looking for a way to plot data points on to a view in Android. Preferably, a library which will do this for arbitrary-ranged input, as well as allow panning and zooming (via pinch or zoom bar).
Right now, I have subclass-ed a view which does the following normalization:
final int width = View.MeasureSpec.getSize(this.widthMeasureSpec);
final int height = View.MeasureSpec.getSize(this.heightMeasureSpec);
final float factorA = width / (maxA - minA);
final float factorS = height / (maxS - minS);
final float constFactorA = factorA * minA;
final float constFactorS = factorS * minS;
final int dataLength = data.length;
for (int i = 0; i < dataLength; ++i) {
if (i % 2 == 0)
_data[i] = _data[i] * factorA - constFactorA;
else
_data[i] = _data[i] * factorS - constFactorS;
}
and a call in onDraw() to the drawPoints method of a canvas (also, I update this.widthMeasureSpec and this.heightMeasureSpec in onMeasure()).
This is with minA/maxA as the bounds for my independent variable and minS/maxS as the bounds for my dependent variable.
This works fine for displaying the data, but I am hoping someone else has solved the problem of drawing the axes and panning/zooming.
I have ~150,000 data points, and I would prefer to keep these as floats to save half the memory. I don't know how big decimal numbers are in JavaScript, but I really don't want to resort to passing data in through JavaScript for the Google Charts API or an HTML-based solution for memory's sake.
I'm running this on a MyTouch 3g (the original, before 3.5mm jack and it's RAM upgrade), so performance is an issue. I'd like to release the final project under the GPLv3, so this excludes GraphView.
The graphs are of the same type as this, so any optimization by excluding points that are too close together to show up on screen would definitely make a difference.
sargas , do check android-misc-widgets.It contains a widget named PlotView with an example TestInterPolator.
Hope it helps.
Original post: Chart and Graph Library for Android
With the library GraphView it's possible to create a line and bar graphs.
GraphView is a library for Android to programmatically create flexible and nice-looking line and bar diagramms. It is easy to understand, to integrate and to customize it.
First checkout the library and integrate it into your project.
Source code is hosted on github.
GraphView library on github
It's also possible to let the graph be scalable (zooming) and scrollable. More information about this library on Original post: Chart and Graph Library for Android
This is how it will look like:
Then you can easily create it with a few lines of code (see snippet):
// graph with dynamically genereated horizontal and vertical labels
GraphView graphView = new LineGraphView(
this // context
, new GraphViewData[] {
new GraphViewData(1, 2.0d)
, new GraphViewData(2, 1.5d)
, new GraphViewData(2.5, 3.0d) // another frequency
, new GraphViewData(3, 2.5d)
, new GraphViewData(4, 1.0d)
, new GraphViewData(5, 3.0d)
} // data
, "GraphViewDemo" // heading
, null // dynamic labels
, null // dynamic labels
);
LinearLayout layout = (LinearLayout) findViewById(R.id.graph1);
layout.addView(graphView);
There is http://www.jfree.org/jfreechart/ which can suit your needs, it is a Java library so it should fit nice to Android. And it is LGPL.
If you can go the JavaScript route, then you could check out ProtoVis http://vis.stanford.edu/protovis/