Implementing a horizontal scrollable HomeScreen widget?

Most Android devices have a home screen that you can scroll horizontally by dragging and dropping (there are others that have a grid-like scroll function, like 2g, but I'm only interested in horizontal scrolling).

Can someone shed light on me, how can this be achieved?

At first I thought about using a custom ViewFlipper. I could attach a suitable slide animation to it, but this is not quite the same. On the main screen, the "number of sliding" depends on how far you drag your finger on the screen. Animations are things with fire and forget, I can not stop them halfway.

Any ideas?

Here's a video about the desired behavior: http://www.youtube.com/watch?v=UGdWM2TQNSo&feature=player_detailpage#t=104s

+4
source share
2 answers

You can take a look at how the Android Launcher Android app does it here: https://android.googlesource.com/platform/packages/apps/Launcher2/+/master/src/com/android/launcher2/Workspace.java

You are particularly interested in the onTouchEvent , onInterceptTouchEvent and computeScroll .

+3
source

Google has released a compatibility pack with some new user interface elements that can be downloaded using the SDK manager.

  • put the .jar file located in sdkfolder/extras/compatibility in your build path.

  • you can now use a class called ViewPager that behaves like an Android Homescreen.

Or, if you use the Eclipse plug-in and ADT version 12 or higher, just right-click your project, select “Android Tools”, and then “add compatibility package”.

0
source

Source: https://habr.com/ru/post/1342704/


All Articles