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.
Related
The questions are quite FAQ-type, but I can't find any suitable tutorial and don't even know what exactly to search for
1) I've got a list filled with linearLayouts and need to set an animation for elements added to those layouts as shown on image. The animation is the element slides from under the existing layout elements. If an element is removed, the animation is the same reversed
2) There is a screen filled with elements. Tapping, for example, a certain button, you call a pop-up, which comes from the edge of the screen and is above the rest of the elements.
If you tap anywhere, except the pop-up,
a) it will slide back
b) you will interact with the objects which the pop-up does not cover
What makes such effects possible? How to implement them and what to read about?
For 1) Setting animateLayoutChanges=true for LinearLayout should do the job
For 2) You can open a Dialog on button click and customise the animations for the dialog by calling dialog.getWindow().setWindowAnimations('id of animation xml')
Had a question about making part of a View Always-On-Top. Please see the Groupon picture below. The black window at the bottom where it says "From $29" & "Buy!" is always on top of the activity page. Meaning the rest of the page is scrollable above that black window at the bottom. Please note I only want this activity to have an Always-On-Top
How do I make a portion of the activity Always On Top? And what kind of layout did you think they used for Groupon? I was just going to make a RelativeLayout and layout_alignParentBottom="true".
You could probably get away with having a vertical linear layout with two children. The first one a scrollable area and the bottom a view with whatever it is you want to be 'on top'. Since there's no transparency there's no visual difference between having the black view as always-on-top and having one view on top of the other (in the y-axis, not z-axis). Plus, if you do it this way you can reach and see the bottom of the scrollable view's content.
To the best of my knowledge, the best way to do this is by implementing a BaseActivity with this View, and have all your activities extend this activity instead of the standard Activity.
I am having great trouble to implement layout swiping UI. Here I show you how each layout works.
My first Layout
My second layout
My third Layout
How it works:
A user can move one page to another by touching the screen and the indicator will move as the layout or page move. But the Sign In and Sign Up button will be fixed in there position. How can I implement this type of UI.
This can be done using a viewFlipper but there is a trick using this whole as a layout.
Use a frameLayout
having your buttons settled down with the gravity set to bottom
Note framelayout works as a stack LIFO things(widgets/layouts) placed at last will superimpose the ones place above them in xml
like for example
//so here view shows s2 and below that s1.....
so in your layout s2 will be the buttons with gravity as bottom
s1 -should be a viewFlipper ...
SWIPPING
swipping can be acheived using the onTouch event
SWIPE LEFT
When the touch down gives a position(x1,y1) and onTouchUp (x2,y2)
check if(x2>x1)
so use viewFlipper.setInAnimation(Animation) viewFlipper.setOutAnimation(Animation)--for the ui that will be gone
SWIPE RIGHT
similarly if (x2<x1)
viewFlipper.setInAnimation(Animation) viewFlipper.setOutAnimation(Animation)
You have used three different layout and increment counter by touching the layout and match to set the layout.
Here is the complete example of ViewFlow please check out the source
https://github.com/pakerfeldt/android-viewflow
and here is another example
http://developer.android.com/shareables/training/Animations.zip
see implementation of screen slide, that is what you exactly want.
The bar moves something like this
Display d= getWindowManager().getDefaultDisplay();
int h=d.getHeight();
int w=d.getWidth();
after getting this h and w , now at every swipe move the bar
where w=screen width calculated with the above method
increments=w/3;
bar_initial_position+=increments;
so it moves..
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.
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!