I'm new to Android and need advice. I have a GridLayout with multiple ImageViews. Each ImageView has a drawable and a background color. On button click, I want to animate two things, depending on user's input: 1) move the entire view to a new position (this part is clear and doesn't cause problems), and 2) move only the image's drawable to a new cell, leaving the view with the background color at the original position. I'm completely stuck on this second task. How do I move drawables using animation? Thanks for any help.
move only the image's drawable to a new cell, leaving the view with the background color at the original position
I think you can't "move a drawable". But you can do the following:
introduce a View - let's call it movingDrawableView - showing just the drawable but with a transparent background, this View is hidden at first
Set the position of this movingDrawableView to overlap the View with the drawable and the colored background and make it visible
Set the drawable of the View with the colored background to null
start the animation for movingDrawableView
as soon as the animation is finished, fill the underlying View with the drawable and show a background as required
hide movingDrawableView
Related
Drawing App
when i put bitmap background on view i fill the color using finger and i select the erase button that will be also remove color and car image what should i do please help me i only remove color not bitmap image from the background
See the image]1
Add two views one for background and one for color so if you erase in one view it will not affect the below view
I want to create a custom view which should have animation. I want to draw the circle with specifying the radius and some drawable element in this custom view which should be moving in this circle.
I know how to draw a circle, how to add a drawable element, but I don`t know how to animate this drawable element.
Should I write animation methods in custom view or better to create another class with animation logics and apply it to my custom view. Can you give me some advice?
I think that second case is wrong because in this way a whole view will be animating, but not only drawable.
I have a custom view like a circle's quadrant. I wish to fill color in the view sequentially starting from left. How do I go about coding this animation?
My application has a big button with an oval shape as background, it is runtime created. Let's name this button A.
When I enable some function the visibility of A is set to GONE, and four smaller buttons are shown, with the same background of A.
When I hide the buttons and show A again, it has proper size, but the background drawable is still of the size of the smaller buttons previously drawn. How can i resize it so that it fills the size of the A button?
Update: My code
//BigButton.java
//...
GradientDrawable idle = new GradientDrawable();
idle.setColor(Color.rgb(red, green, blue));
idle.setShape(GradientDrawable.OVAL);
idle.setStroke(2, Color.rgb(red2, green2, blue2));
btn.setWidth(50*3f);
btn.setHeight(65*3f);
btn.setBackgroundDrawable(idle);
//...
//ChildButton.java
//...
GradientDrawable idle = BigButton.this.getIdleDrawable();
btn2.setWidth(50);
btn2.setHeight(65);
btn2.setBackgroundDrawable(idle);
//...
Update2: The following creates a new drawable so that there's no resource sharing between parent and child buttons.
GradientDrawable idle = (GradientDrawable) ButtonSetupPanel.this.caller.getIdle().getConstantState().newDrawable();
You're using the same reference for both buttons. Use two different references, but with the same settings. This way changes to the drawable for the small button won't be visible on the big and vice versa.
I have a RelativeLayout filling the screen and a couple of ImageView positioned on it using LayoutParams margins. These ImageView are animated in different ways, and in one case I want an image to "fly in" to the screen from the right.
Unfortunately, if I set leftMargin for that ImageView greater than the width of the screen, it does not appear (or appears cropped if it partially visible at the start of animation).
I tried setting width and height of RelativeLayout to be bigger than screen size - it works, but only partially: if the image is positioned completely off-screen, it does not work, and if the image is partially visible, it is not cropped, but that works only for right and bottom sides.
So, my question is this: how to position several ImageViews on and off the screen so that I can animate them using Animation?
In the end, I used a trick: I combined AnimationDrawable and view animation. I did the following (assuming that the animation has to run T milliseconds):
Position that ImageView on-screen.
Set as its background an AnimationDrawable with following frames:
empty Drawable: 1ms,
normal Drawable: Tms.
Change view's animation to this:
jump to off-screen position (translation with duration=1ms),
do normal animation.
This is probably a good place to start looking for those who would use Fixpoint's solution.
Android — How to position View off-screen?