Android 类似 Tweetdeck 的 UI
我正在开始进行Android开发,我希望有一个类似于tweetdeck的界面:有几个从左到右布局的工作区(活动),用户可以通过水平手势在它们之间切换。 Android 桌面切换方式相同。
在 tweetdeck 中,标题栏中也有一些点,表示在哪一侧以及有多少个工作区。
它是标准的 Android 界面,还是定制的界面?我该如何做这样的事情?
I'm getting started with Android development, and I would like to have an interface similar to that of tweetdeck: there are several workspaces (activities) that are laid out left to right, and the user can switch between them with a horizontal gesture. The same way the Android desktops are switched.
In tweetdeck there are also dots in the titlebar, that indicate on which side and how many workspaces there are.
Is it a standard Android interface, or something custom built? How do I do something like this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您如何进行此操作将部分取决于您想要呈现的内容。如果有很多重量级页面,您需要考虑执行自定义
AdapterView
。如果只有几个固定页面(例如在库存主屏幕中),您可以将其视为可滚动视图,并使用一些自定义逻辑来处理页面对齐。以下是在 Android 原生启动器中实现此功能的自定义视图的链接。您感兴趣的部分主要位于
onTouchEvent
、onInterceptTouchEvent
和computeScroll
中。https:// android.googlesource.com/platform/packages/apps/Launcher2/+/master/src/com/android/launcher2/Workspace.java
How you go about this is going to be partially dependent on the content you want to present. If there are going to be many heavyweight pages you'll want to look into doing something like a custom
AdapterView
. If there are only a few fixed pages such as in the stock home screen you can treat it like a scrollable view with some custom logic to handle snapping to pages.Here's a link to the custom view that implements this in the stock Android launcher. The bits you're interested in will mostly be in
onTouchEvent
,onInterceptTouchEvent
, andcomputeScroll
.https://android.googlesource.com/platform/packages/apps/Launcher2/+/master/src/com/android/launcher2/Workspace.java
看看 ViewFlipper: http://developer.android.com/reference/android /widget/ViewFlipper.html
Take a look at ViewFlipper: http://developer.android.com/reference/android/widget/ViewFlipper.html
除了研究实际的 Android 代码(在另一个答案中引用)之外,一些人还提取了工作区(Launcher2)代码并将其隔离到可重用的视图组中。您可以在 github 中找到该作品 https://github.com/olibye/AndroViews
In addition to studying the actual Android code (referenced in another answer), some folks have extracted and isolated the workspace (Launcher2) code into a re-usable view group. You can find the work in github here https://github.com/olibye/AndroViews