Find some trouble with android animation.
I have layout with RelativeLayout as root and have four ImageView's allocated in center of layout, and on top of them i have some picture.
Next i have some button and then in activity i make run next code
RotateAnimation anim2=new RotateAnimation(0, 360,Animation.RELATIVE_TO_SELF,0.5f,Animation.RELATIVE_TO_SELF,0.5f);
anim2.setFillEnabled(true);
anim2.setFillAfter(true);
anim2.setDuration(100);
ImageView animatedView1 = (ImageView) findViewById(R.id.imageView1);
animatedView1.startAnimation(anim2);
animation work with lags :(
Like i try run Doom 3 on S3 Trio video card :)))
But if i hide else 3 imageviews and show only one image wich i need to be rotated - i have no problems - it rotates smooth and how i need.
Also i found what it's no different size of images (files) 6 Kb,60Kb it's no difference :(
How i can do rigth animation with no LAGS
Related
I have this weird behavior that I cannot find a solution around...
This only happens in my emulator API Level 10, on my smartphone (Android 4.1) works fine.
I wrote a dynamic animation to show a rolling dice, where 10 random frames are chosen as the frames of the animation, with a duration of 50ms.
When I press the button, the animation run, but squeezed into zero height..... (You can still see some colors from the animating dice), the layout also get messed up.
This does not happen on my phone though.
Here is the portion of the java code:
public void RollDice(View view) {
int id=-1;
AnimationDrawable diceAnimation = new AnimationDrawable();
//create 10 random frames from dice1.jpg to dice6.jpg into diceAnimation
for(int j=0;j<10;j++){
id=getResources().getIdentifier("dice"+String.valueOf(rng.nextInt(6)+1), "drawable", getPackageName());
diceAnimation.addFrame(getResources().getDrawable(id), 50);
}
//assigning and starting animation
diceAnimation.setOneShot(true);
dice.setImageDrawable(diceAnimation);
diceAnimation.start();
}
and the portion of the xml:
<ImageView
android:id="#+id/Dice1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:contentDescription="#string/diceimage"
android:src="#drawable/dice1" />
The button onclick call RollDice().
As final remark, IF I hardcode in ImageView, say android:layout_height="100dp", then the dice will show during animation, but streched into funny shape...
I tried most scaling method, adjustviewbound etc with no luck...
I don't know whether your problem is solved or not.
But I would like to add the answer to this question.
You can try this :
Firstly , set you image view layout_width from match_parent to wrap_content.
Second make use of this below code so as to make the dice disappear completely :
frameAnimation.setVisibility(GONE);
Might have an answer for your, try it out with caution, since I'm a beginner myself.
ViewGroup.MarginLayoutParams mParams = new ViewGroup.MarginLayoutParams(view.getLayoutParams());
ImageView view = (ImageView)findViewById(R.id.image_dice);
layoutParams = new RelativeLayout.LayoutParams(mParams);
layoutParams.width=120;
layoutParams.height=120;
view.setLayoutParams(layoutParams);
Applying that to your image will adjust the .xml on the fly, atleast it works for me when I'm grabbing alot of differently sized images from the web.
I have a bunch of dynamically created ImageViews representing different objects in a game, which is working fine. However if any Image reaches the edge of the screen, it shrinks. Looks like android is attempting to create a smooth transition, but this is not wanted.
I found another thread with the same issue here: Animation Drawable gets automatically shrinks at the corners ?, however his solution does not work for me, it only enhances the issue as it starts shrinking once the margin hits the screen edge.
This is my code:
final LayoutParams _updated_params = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
_updated_params.setMargins((int)m_x, (int)m_y, 0, 0);
m_image.setLayoutParams(_updated_params);</code>
Where m_x/m_y is the absolute position of the image and m_image is an ImageView instance.
Does anyone know how I can turn off this automatic resizing?
Add setScaleType
m_image.setScaleType(ScaleType.MATRIX);
Use setScaleType
m_image.setScaleType(ScaleType.FIT_XY);
I have these 2 pictures:
and I´m trying to make an animation of them. I want to show the first picture (the one without wheels) and then the one with booth wheels. It shall be looking like the wheels have appeared, because the position will not be changed and the car shall not disappear. So I tried to use fade-in effect, because if I just "reload" my xml layout, it doesnt look very good.
I found many tutorials, but none of them did solve my problem. My question is: Does anybody know, how to do that?
use FrameLayout to stack two ImageView always show your first picture the one without weels and use any action listener to triger the animation on second ImageView using AlphaAnimation..
Animation animation = new AlphaAnimation(0.0f, 1.0f);
animation.setDuration(1000); // anim duration in milli second
animation.setRepeatCount(0); // 0 no repeat
animation.setFillAfter(true);
iv.startAnimation(animation); // iv is your imageview
Take a look at this design I did for an interface of a game I want to develop on Android:
http://www.moboing.com/smallshow.jpg
When a user touches a balloon, I want that star/glare animation to play with the stars dropping down. All I'm curious about is the best general direction/approach to making that animation possible while developing the app in eclipse/java.
I was thinking making a few variations of stars as transparent PNG's, and making them animate on touch but I'm a newbie so I'm not entirely sure.
You can create the animation like a sequence of images and then use the AnimationDrawable class to make it animated. Let me show you an example:
ImageView my_image = (ImageView) findViewById(R.id.my_animation);
AnimationDrawable animation = new AnimationDrawable();
// We need to add each image to our final animation setting time interval between them
animation.addFrame(getResources().getDrawable(R.drawable.img_1), 200);
animation.addFrame(getResources().getDrawable(R.drawable.img_2), 200);
animation.addFrame(getResources().getDrawable(R.drawable.img_3), 200);
animation.setOneShot(false);
my_image.setBackgroundDrawable(animation); // Set as background to see it
animation.start(); // Start playing the animation
Where:
my_animation: your ImageView into your desire Layout.
img_1, img_2, img_3: images that compounds your animation (your should
create and save them into res/drawable folder).
I hope it can help you and draw a way to do it by yourself :)
PS: this should be into a method on the activity that you want (for example, into onCreate to show it when user start).
I have made a set of 3 images that will represent the move of a animal. Each image represents a frame and consists only in the animal with transparent background.
I have made a AnimationDrawable in code and created the animation:
AnimationDrawable staticAnimation = new AnimationDrawable();
staticAnimation.addFrame(ctx.getResources().getDrawable("frame1"),150);
staticAnimation.addFrame(ctx.getResources().getDrawable("frame2"),150);
staticAnimation.addFrame(ctx.getResources().getDrawable("frame3"),150);
I set the animation as a background for a Imageview and start it
imgAnimal.setBackgroundDrawable(staticAnimation );
staticAnimation.start()
Because the frames have different width (the drawing needs to recreate steps move) looks like the Imageview resizes the images in the animation. Better to say, if frame1 is bigger then frame2, frame 1 is displayed ok but frame 2 is stretched to be as big as frame1 was. Looks really awful.
Any suggestions on how to stop this behavior ? Thank you.
The solution was quite simple, because images in frames have same height but different width, I simply made a transparent border rectangle and put it over each frame. In this case each frame will have the same width and the animatin will run as supposed to.