Swipe for activities in Android - android

I am trying to build an app in which I want to go to a new page through swipe-say. I have about 10 different pages and I want to go to these pages by swiping. Can I implement these pages as separate activities? Can I swipe from one activity to another? I strongly like to implement these pages in seperate xml files rather than creating everything in a single xml page. But as far as I have searched, there are no proper tutorials or blogs giving an appropriate example of a program implementing swipe. If possible, provide some working codes.
Thanks in advance.

It seems that a FragmentPager is what you want.
Examples and code on the linked page.
If you build for earlier versions of Android, the necessary code is included in the Android Support Package.

In Android, swipe is not identified as a particular gesture.
You can use a OnTouchListener registered on your view, and animate your view if the gesture exeeds a certain threshold.
You can then launch a new activity, or in a simpler way, use a viewFlipper.

Please try the attached link View flow.
I feel it will fit your needs perfectly. You can even create different xmls and inflate them into different view objects and then use the "view flow" to switch between them.
The "view flow" is perfect for handling both simple & complicated views. The flow indicator on the top of the screen is optional.
I hope it helps..

Related

Create UI like Chrome for Android

I want to implement this behaviour [https://github.com/gleue/TGLStackedViewController] in an app that I am trying to make.
The closest thing/the effect that I want to achieve is how the Google Chrome browser behaves.
Tile/card interface
Be able to access a form of navigation (access other tabs) when user pulls down the address bar
Be able to re-arrange the tabs in any order the user wishes
Photo taken from this Android Layout : How to implement a UI similar to deck of cards? SO question
Is there anyone out there who has tried to implement this kind of behavior? Do you guys know any libraries that can help achieve this effect? It would be very helpful! Thank you
systemUI/Recents package, as mentioned by Andrei, can be your starting point. It adds a little more to the flat rendition of chrome tabs.
I have been meaning to refactor systemUI/Recents package ever since I got the L update. I finally got to it.
A sample project is hosted at: Link
Even though the viewgroup recycles, it updates the progress map (child properties) for all children on each scroll step. This will lead to lags with large data sets. For a few hundred, it should be fine.
The sample project uses Picasso for loading and caching images from LoremPixel. Since these are random images & may repeat, you can verify that they are bound correctly by looking at bottom left of the image.
If you feel like looking through the AOSP code, the functionality you are looking for is actually open-source and you can find it in Android 5.0 in the recent apps screen. This is the code you want to look at on github.
The view you want to extract from AOSP is the RecentsView. This would be the best approach.
You could also consider extending StackView and overriding onLayout() so you get the children to lineup.
One other option is to extend ListView, override drawChild or layout methots and try to shift the views according to their position. You can find some inspiration here and here

How to implement Tabs UI in android

I have existed code for two activities(ActivityA and ActivityB).
Now I need to have a another activity, which will act as my first and only screen of my application. This activity will be having two tabs on its header part and I need to display each of my Activity when user press on each tab.
I have done some search on this and found TabAcivity will be suitable choice, but it is deprecated now.
I saw many posts which are suggesting Fragments. But I dont want to change my existing code. Can any one suggest me easy method to incorporate this.
you can use Android Tab Layout with Swipeable Views
here i give Link in this link step by step information given. so i think you can get batter idea from that.
Tab Layout with Swipeable Views
you can also download code from this site and also see video in given sit

Switch from one page to another

I'm new to Android programming and I'm working on my first application "FunFacts" where
there should be more than 100 cool things to learn about nature, science etc.
My question is: How can I switch from one page to another using two buttons "left" and "right"? which method should I use? I don't think that a horizontal scrollview is the solution.
So if I have 2 different layouts, page one and page two, how can I switch from one to other in my application?
Thank you!
It sounds like you might want a ViewPager. Below is a link to the Android tutorial. This creates a slideshow type effect which sounds like what you're going for. You said you will have different layouts which this will use one layout but you can customize the content and I would think you would want one so it all looks relatively the same
Docs
Update
No, you don't have to create 100 layouts or activities. Just one of each. Following will be a link to a post that explains it a little better. That post explains how it is like a listview in that you add the different pages to your view adapter as you would with a list. You can use the same layout for all and just add new data to it (like a list). Probably store them in an ArrayList or possibly a DB if you have that many and want to have a lot of data attached to them. I hope this makes sense and helps a little. I would suggest starting one with just a couple pages to see how it works, following these examples, and if you get stuck then post a more specific question as to what you can't get to work.
Link

Android - Multiple activities under a single tab, Fragments

After scanning all the related questions regarding multiple activities under one tab, I found out that they all refer to using ActivityGroup which is deprecated.
Basically I have 2 tabs, the first one contains a main activity with several buttons and when button is clicked 1 for instance a new activity should open under the same tab, clicking back should bring me to the main view under the first tab. The second tab contains only one activity.
Tried inflating a new view for the sub-activities:
FrameLayout frameLayout = tabHost.getTabContentView();
frameLayout.removeAllViews();
View view = getLayoutInflater().inflate(layoutID, tabHost, false);
frameLayout.addView(view);
But I only get the view, I cannot handle it like an activity; meaning adding buttons or listeners, it's only a view.
Google suggests using fragments instead, but I am having the hard time implementing this. Maybe replacing the activities with fragments could be the solution.
I could really use a good tab\fragments example right about now...
Any suggestions? Thanks in advance.
Yes, the solution to your problem is using Android Fragments.
I understand that you have trouble figuring out what to do. It's everybody's difficulty actually. However, with enough patience to google out things, you will realize it's actually not that difficult.
What I will be telling is basically some tips on how to change your code to fragments. From your current code, there's actually a major change you need to do but it's worth it.
What you are doing is actually you're making a dynamic UI. You have chunks of fragments which eventually can have different listeners which you should later on defined. Here's a sample demo you can actually wok on.
If you want a detailed tutorial, I followed this one. And, yes, it works!
Have fun learning Android and don't forget Android is directly linked to Google. And you can easily google things and ask specific questions here should that question was never asked before.

How to implement swipe pages [duplicate]

I'd like to make a view in my Android app that flips between multiple views on a swipe/fling. I'd like it to behave more or less like the Android Launcher behaves when flipping between views. In particular,
It should flip views on swipe.
Generally a swipe will flip between one view and the next. It should not fling across all of the views.
If you swipe slowly, you should see the views dragging as you're swiping, eg. the way the Launcher does it.
I tried using a ViewFlipper with a GestureOverlayView as per Romain Guy's blog post here, but there's no indicator to the user as they're swiping. This makes discoverability difficult, which is presumably why Launcher does it the way they do.
I tried using a Gallery object, but when I swipe from left to right, there's a certain amount of momentum that flings the users through all the views rather than just taking them to the next view.
Is there a good way to accomplish what I'm trying to do?
I know this is an old question but ViewPager is created for this exact same purpose. ViewPager is part of android compatibility package and more can be found at http://android-developers.blogspot.com/2011/08/horizontal-view-swiping-with-viewpager.html
Take a look at HorizontalPager. It's actually based on RealViewSwitcher, which in turn is based on the Android homescreen's code, and supports snap-to paging with drag feedback, as well as nested vertically-scrolling subviews. Gesture support for fast swipes isn't all it should be, but this may get you part of the way there (and I'd welcome contributions back).
EDIT: As of 2012 you're much better off using Google's ViewPager - it's in the compat library.
Check out SwipeView within this project https://github.com/fry15/uk.co.jasonfry.android.tools It does exactly what you want it to do and is super simple to implement.
#CommonsGuy extended ViewFlipper to do it.
https://github.com/commonsguy/cwac-viewswiper
Ihaven't used this one yet so im not sure if it moves with your finger like the launcher if not your going to have to make an OnTochListener to do it for you in me.ACTION_MOVE you will update the view to change its position. I'll post some sample code when I get home if you don't get another answer.

Categories

Resources