I want to implement the concept of "Slide to open" concept in my application. Basically, I am using an ImageView. If the user slide it to a specific direction (to the right for example), the next activity is started. I do not know how to implement this in Android, I have searched in lots of place but found nothing.
Any clues ?
What I came into :
No I do not think that the use of ViewPager or HorizontalScrollView is appropriate in this case.
I don't know if the concept of Drag And Drop helps (how to imply a drag in a specific direction ? How to let the ImageView return to its initial location if the drag ends midway ? ...)
Use frame layout and put a ImageView in it. Then add touchEvents to Imageview. update imagViews Layout parameters at ON_MOVE event.This is the basic idea of slide and drag stuff in android.Good luck.
you may use View.Animation for moving back the slider to start position again ON_UP event
you can move view only in x axis by only changing the views :
LayoutParams.leftMargin=event.getRawX();
(always set the gravity to NO_GRAVITY)
If you want to implement smth like "slide to unlock" you can implement drag and drop and forbid moving by Y axis for example. Also you can check image position and analys if this shift is enough to open\unlock, and if not - simple move this image back.
Related
I was trying to implement a drag down listener on my android app, and make a layout which is in view.GONE state animate and increase upto certain height as I drag down.
I tried using OnTouchListener Action Down and Action Up but it is not helping me.
How to achieve this?
Layout1(App_Header)
Layout2(MapView)
Layout3(ViewPager)
Layout 2 is hidden(View.GONE) after pressing a button.
now by dragging down the screen from the header I should get back my Layout2(MapView) increasing its height as I drag down.
I also tried using DragListener to PagerTabStrip on Layout 3, but it didn't work.
Are there any one who can help me on this?
The best way to achieve it is using OnTouchListener and a custom OnDragListener.
Here is a great example and here is another one (from google documentation)
If you need any additional help just ask!
Here is what I wish to implement..
A slider like thing...
Say My app is a game with 4x4 array of level buttons in each screen
and there are totally 3 screens...
The user should be able to swipe his finger from right to left and the
slider should "slide" to next 4x4 set of levels...
Just like what the phone functions while we open apps from homescreen. And if the user swipes his finger from right to left and there are no levels to the left, the slider should bounce back...
So... What I ask is which layout/view/class to use to implement such a slider?
Also, plz inform me how can I implement such a slider which switches between tabs as well (each tab containing different layouts).. I hope I made myself clear...
As i understand you can use:
gallery and for each row create your own viw
ViewPager - like in android market (slide between view)
All of this approaches uses adapters and listeners - you can find a lot of examples in internet. I think in your case viewPager is mor useful, because as i understand you want to have many different views.
I'm trying to implement a sliding menu, like in Prixing app. (The menu which lays under main layout and get visible when you take and drag main layout to the side)
But the trick is - i want it to appear on bottom of the screen, so I need to move the main layout to the top.
The second problem is that in tah layout I got a listview.
Please, I really need advices or maybe link to some usefull resources where I can understand how touch events are handled.
Thx!
i think you are try to do same as facebook app. i have found demo for it. so use this
there's really no magic on it.
To make it, move directly (in a button click or something):
you use a animation to change the LayoutParams.top from both fragments (the one on top (currently in view, and the one on the bottom, hidden under the screen).
On your XML layout make sure to set a fixed height for the bottom layout (in DIP) and during runtime animate the two layouts to move that amount of pixels.
To make it move with the user finger:
That will be tricky, because the listview MUST receive the the user input. Maybe if you call super on it.
But you can accomplish it by receiving OnTouchEvents:
TOUCH_DOWN, you start the move (mark it with a boolean or something)
TOUCH_MOVE, you apply the same change to the layout params that you did on the animation (1st option)
TOUCH_UP or TOUCH_CANCEL, you stop the move (clear the flag).
hope it helps pointing you to the right direction.
I have a text view where in i have to keep ages between 1-99. I also have two buttons ^ and v(i mean up and down arrows) on clicking them the values of the age should smoothly scroll to next or previous value.
I have been trying different ways but couldnt achieve smooth scrolling. Can anyone please give me any idea of how to achieve the task.
I think the easiest way is to simply put the TextView within a ScrollView, and let the arrows interact with the ScrollView, by using things like the fling method and playing around with the velocity parameter to suit your needs.
Use the animation framework.
When pressing down, start the 'down'-animation.
When pressing up, start the 'up'-animation.
Read more about animation here: http://developerlife.com/tutorials/?p=343
View animation is not much matured and hence i am noy sure if that can be used for moving the views.
Please find the description below:
Another disadvantage of the view
animation system is that it only
modified where the View was drawn, and
not the actual View itself. For
instance, if you animated a button to
move across the screen, the button
draws correctly, but the actual
location where you can click the
button does not change, so you have to
implement your own logic to handle
this.
Source
To scroll smoothly you can try using the scroller component.
Reference
What you would need to do is pass the duration of the scroll in the constructor and then use the property
setFinalY(int newY)
to increment the counter position by 1 unit (equal to the height of the item).
Please let me know if that helps!
The views are not cached in a ViewFlipper. Is there a way wherein we can get an image of the view and show it to user so that he sees the Ui as we see on Home scrren(when we swipe the previous view also moves along and when we lift our finger, only then the next view is shown completely.)
What I want to do is that when the user starts moving his finegr on screen, the view should also move along(create an image of view).
I am not getting to do this, as when we swipe the present view goes and next view comes, we do not get both visible when we r moving our finger on screen.
Please if anyone gets what I am trying to do, do help me.
Thanks,
Farha
It's tricky to get scroll and swipe tracking working on Android, while using ViewAnimator or its subclasses.
They allow you to set in and out animations and start them at a given moment, but they work with discrete, either-this-or-the-other-view animations. They are actually using FrameLayout and after in or out animation is executed, other views' visibility is set to View.GONE to hide them from showing up under/over your current View.
The Launcher and the Gallery application are actually doing the functionality you want, by using a different approach.
They track the user touch input (onTouchEvent()), on MotionEvent.ACTION_MOVE they perform animations manually and on MotionEvent.ACTION_UP snap to the appropriate view, just like in the iPhone.
Unfortunately, this approach is actually more complicated than it looks like.
With the manual handling, you have to ensure that you are taking care of everything related to the touch input. This includes a lot of flag-raising, value-checking, event-delegating, etc.
If you want to get better acquainted with this, take a look at these classes from Gallery3D or Launcher's source code.
One other way to get nice horizontal scrolling is to use HorizontalScrollView.
You have to figure out a way to recycle your views, like you would with a ListView and you have to add the snap-to-view logic, but if you have to take care of a small number of views it could be the easiest approach.
Hope that helps.