I have a button that the user can drag around. When the button is moved out of the view it seems to clip the image that is in the button's background. If I then animate the partially offscreen button using TranslateAnimation the clipped image moves through the animation.
How can I ensure the background gets fully redrawn as the image animates to another position?
Add android:clipChildren="false" to the parent xml node.
Related
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
I have a view and two buttons which are used to slide up the view to the screen and the other button to slide it down. But if I keep pressing the buttons alternately the view does not return to its original position but is displaced.Here is the code
//button 1
Interpolator interpolator=new OvershootInterpolator();
loginOptionsSheet.animate().translationYBy(-loginOptionsSheet.getHeight()).setDuration(550).setInterpolator(interpolator)
.start();
//button 2
Interpolator interpolator=new FastOutLinearInInterpolator();
loginOptionsSheet.animate().translationYBy(683).setDuration(300).setInterpolator(interpolator)
.start();
When you keep pressing the buttons, you are starting the animation over again in the middle of animating, and since you are using translationYBy the "origin" keeps moving as the animation restarts.
From the documentation
The amount to be animated by, as an offset from the current value
So use translationY instead
The value to be animated to
Note that you will have to change your values around as you will now be translating to the absolute position now instead of putting in the relative amount to change.
I'm trying to do a TweenAnimation (Scale and translate) with two ImageViews (top and bottom). Each ImageView (and some other stuff) is in a RelativeLayout and the RelativeLayouts are in a LinearLayout. The images moves to the left top corner of the display. The Animation works fine, but at the end of the (Relative) Layout the animation disappears (in the mid of the display).
Is there any way to give the animation more (all) space then only the parent View? Thanks!
You can set the parent view to not clip it's children and allow them to draw outside it's bounds. In your XML, add this:
android:clipChildren="false"
I have a LinearLayout [Horizontal Orientation] in which I have several ImageView objects side by side. I need to be able to drag the ImageView objects side to side.
I can drag them, but I need to be able to draw them ontop of each other as I am dragging.
So, if I have
(imageA)(imageB) side by side, and I am dragging imageA in the direction of imageB, I need imageA to draw on top of imageB and viceversa.
So far, I can get the dragging done no problem [by extending ImageView, capturing onTouchEvent, overwriting the onDraw method, and translating the canvas] however, as soon as the ImageView is moved, it is clipped because of its bounds. I try setting new bounds for the drawable of the ImageView but that doesn't work either.
How do I draw one ImageView on top of another ImageView [without using FrameLayout] ?
Thanks,
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?