1

I am new to android XML layout and trying to make a layout that is similar to windows phone home screen. Following image tells what i am looking for.

swiping should change the view

What I have tried,

1) Horizontal Scroll View: this works for left-right swipe until the grid or list does not have a vertical scroll bar

2) Linear Layout with orientation Horizontal: Same issue as above

Harshit
  • 661
  • 5
  • 16

2 Answers2

1

You can use a gesture detector to detect a swipe left or right.

http://developer.android.com/training/gestures/detector.html

You can then add an animation to animate the movement from one view to the other. How this works varies depending on how your layout is structured ( i.e. two views in one layout with one hidden, fragments that get swapped out ). There are a lot of examples on stack overflow.

swap fragment in an activity via animation

There is a Gallery View, but this is deprecated in API 16. They suggest ViewPager or HorizontalScrollView neither of which really provides the same functionality.

http://developer.android.com/reference/android/widget/Gallery.html

Here are some other options that I personally have not used.

Options for replacing the deprecated Gallery

Community
  • 1
  • 1
mjstam
  • 1,049
  • 1
  • 6
  • 5
  • so basically i keep two views in a relative layout (or do i need any other layout) and fill them to parent, one being invisible. and on each view's swipe i toggle there state... – Harshit Dec 02 '15 at 17:11
  • You can keep two views in a single relative layout or you can use two fragments and swap them when you detect the gesture. The animations are a little different depending on your approach. Other than the example included try searching "slide animation hidden view android" on google. You will find a ton of examples. – mjstam Dec 02 '15 at 17:20
  • this solutin allows the swipe but causes another issue where list and grid box do not scroll. I think this is because of the onScroll being overridden by SimpleOnGestureListener. I tried to return true from onScroll but the list and grid do not scroll – Harshit Dec 02 '15 at 18:27
  • 1
    I assume you hook the GestureDector up in onTouchEvent and you are still passing the events by calling super.onTouchEvent() – mjstam Dec 02 '15 at 18:47
  • I did that.. but was not working. I have switched to viewpager controll – Harshit Dec 05 '15 at 08:09
0

I got this working using the ViewPager controller available in android

working code can be found here https://github.com/harshitgoel96/ZoZo-Launcher-2

its still a work in progress, but my main two page start is working as expected.

Harshit
  • 661
  • 5
  • 16