AdamM
AdamM

Reputation: 4430

Android scaling image vertically

I am trying to create a mini progress bar that will indicate how much data a user has used. It doesn't even need to animate, I just need it to change in size based on a variable I have set up. So when I load up the screen, how much of the progress bar is filled up will depend on a variable I have set up in Java.

I have managed to get this working horizontally by using

scale =  new ScaleAnimation(0.0f, 1.5f, 1.0f, 1.0f,1.0f, 1.0f);

This will start the image from nothing and stretching out to its full size, so I can use it as a horizontal progress bar which is great.

Now I woulda thought doing this vertically instead would be a simple matter of just changing the fromY to 0 and the toY to the new size I want. However when I do this, by changing the fromY to 0.0f and the toY to 2.0f, the image actually moves and stretches at the same time rather than stretching. Also the image moves position for some reason. It starts off higher up than where I positioned in using XML, and moves down to the original position and stretches out to the new scale I set up.

The code I use to try and stretch it vertically is

scale =  new ScaleAnimation(1.0f, 1.0f, 0.0f, 2.0f, 1.0f, 1.0f);

So can someone please explain why it stretches horizontally fine, but when I try to stretch it vertically, it suddenly moves and stretchs at the same time.

Would be very grateful for any help.

Upvotes: 1

Views: 474

Answers (1)

kingraam
kingraam

Reputation: 1521

I appreciate you have solved the animation issue you mentioned, but based on you saying you don't even need the bar to animate, the ClipDrawable class may make your life simpler. You can define one in an xml layout and then set the clip level from your code, which will clip the given drawable by the given amount.

Check this out for more details on how to use it:

http://developer.android.com/guide/topics/resources/drawable-resource.html#Clip

Hope that's of some help.

Upvotes: 1

Related Questions