Moving imageview from top to bottom in android - android

I Have an ImageView in Center of my Screen, which i want to move up. where it remains at the Top.
I saw Tween Animation Documents and Tried it But Its Not Working.
Can any one Plz help me out solving this issue.

did you tried view animation?
Animation an = new TranslateAnimation(fromX,fromY,toX,toY);//0,0 is the current coordinates
an.setFillAfter(true);// to keep the state after animation is finished
yourView.startAnimation(an);// to start animation obviously
to make it move from bottom to top, get screen height and use it to set "toY" parameter.
after few tries you will sure do it.

Related

How to do a scroll animation in Android?

I'm new to Android programming. I'm working on an app that requires some form of animation. Please take a look at
I want an animation where a scroll rolls down at the top with this text in it as soon as this activity starts & rolls up when the connect button is pressed. I have no clue where or how to begin with the animation. Any kind of links to tutorials or posts on StackOverflow will be of much help.
Thank you for your time!
Since your question is really really broad, I'll give you a broad answer as well.
I think by "scrolling animation" you mean an animation in which a black (or some other color) area slowly covers up/reveals the screen. I don't know why would this look cool, but whatever.
Step 1
Create an animation XML file. In this file, you would specify that the view should translate downwards by x pixels where x is the height of the screen. And create another animation file. This time, specify that it should translate upwards.
If you need help creating XML view animations, have a look here
Now you have two animations - move upwards and downwards.
Step 2
Okay, now you should create a custom view. You can start by doing this:
public class ScrollingView extends View {
}
And implement all the required constructors.
Override onDraw like this:
cover the whole view with black or some other color
draw the scroll at the top of the view. The scroll should be an image like this one:
If you don't like using an image, you can draw it yourself, using code!
You can get help on this here
Step 3
In onCreate of your activity, create a ScrollingView. This view should be as wide as the screen and as high as the screen. Position the view at (0, 0) and bring it to front so that it covers up the whole screen.
Step 4
Next, apply the animation you created in step 1 to the scrolling view.

Alpha fade direction on Android

Is it possible to change the alpha value of an ImageView along a specific direction i.e. from top to bottom or bottom to top on Android?
I am trying to animate with imageView.animate().alpha(0).setDuration(500).start();
however this just fades the entire view out uniformly, but I'd like to do this form top to bottom instead.
Any help appreciated.
As far as I know, it is not (yet) possible with the Android built in animations. You will have to create your own custom animation.
Haven't tried, but maybe you can achieve this by using the Transformation class, and/or overriding the onApplyTransformation method from the AlphaAnimation class
method.

SlidingUpPanelLayout with gravity=top wont snap in at bottom

The question is about com.sothree.slidinguppanel.SlidingUpPanelLayout.
I used the layout with the gravity=top to make the slidingPanel apear at the top of the main context.
But now the slidingPanel does not snap in, when it is moved to the bottom.
It immediately goes returns to the top.
It only snaps in when I drag it a little bit down and then release it.
Seems like the panel has an offset after which it snaps in, which is measured from the bottom.
Event if the slidingPanel is at the top.
Do someone know how to repair that?
The problem with the behaviour I described is with the min. velocity which is required to detect a fling.
Set DEFAULT_MIN_FLING_VELOCITY=0 to make the Sliding Panel expand, after user releases it on any height.

Panoramic Background animation in Android

I have a panoramic background as a sky that i want to move from left to right and then from right to left to simulate a moving clouds animation as a screen background .
This should repeat indefinitely and after goin to the right most then return back to the left most..
I have tried the following:
Animation left = AnimationUtils.loadAnimation(MainActivity.this, com.icare.kids.R.anim.view_transition_out_right);
left.setRepeatCount(Animation.INFINITE);
left.setRepeatMode(Animation.REVERSE);
left.setDuration(3000);
findViewById(id.cloud).startAnimation(left);
But this does not seem to work... any solution for that ?
I am currently setting the image to an ImageView as follows:
<ImageView
android:id="#+id/cloud"
android:layout_width="3000dip"
android:layout_height="wrap_content"
android:layout_below="#id/topbar"
android:scaleType="matrix"
android:src="#drawable/bgpan" />
how can i set the image to the screen to start from the left most like this below, so to help in the panoramic animation effect:
The best solution that is efficient and fast on all phone ranges was to actually only animate the clouds while keeping the background static.
you can also add some variable to the speed that would add some randomization to the speed of the clouds so you don't get a monotonic looping.
Implementation details and solution was taken from this answer
One thing you might be able to try is using a Viewpager object with fake drag, where you continually re-add the background to new views that get generated, while disabling user input.
This will give the illusion of what you are trying to do.
So lets say you have 4 views in your adapter, each view contains just one of the image assets that fills the whole screen, and Viewpager's fake drag pans from View A to View B, draws View C and draws View D, then it fake drags from View B to View C and draws View A again
I'm curious if that would work for you

Android: Animating View position

I'm trying to do something which seems simple. I want to have a map view, with a menu that slides up from the bottom of the screen where settings (for overlay) can be adjusted. However when I use a TranslateAnimation to affect the y position of the LinearLayout (which holds the menu), the buttons in the LinearLayout move, but there "hit area" stays in the same position as they were before the animation.
TranslateAnimation slide = new TranslateAnimation(0,0,0,0);
slide.setDuration(300);
slide.setFillAfter(true);
pullupMenu.startAnimation(slide);
mapContainer.startAnimation(slide);
I've also looked into tweening the view's marginTop value, but haven't even been able to determine how that would be done.
Any help on either of these directions would be much appreciated.
The animation in general is animating the pixels of the widget. My suspicion, based on what you wrote, is that setFillAfter() merely arranges for the pixels to stay in the destination location, not the widget itself.
If you want the animation to actually wind up moving the widget, you need to:
Register a listener to find out when the animation ends, and
Arrange at that point to modify the layout rules such that the widget actually exists in the new location
You can see a sliding pane that employs this technique here.

Categories

Resources