我正在为 watch (ZGPAX S6)编写一个Android应用程序。屏幕非常小,Android SDK 14 目标。我打算运行这个应用程序,顶部没有标题栏或选项卡。这将是一个全屏应用程序 - 1.54 英寸屏幕上的空间非常宝贵。
我心中有一个布局,但应用程序中有 10 个或更多“屏幕”。 是否可以管理“逻辑 fragment ”,而不是将所有内容实际放置在布局 xml 文件中?
例如,我的屏幕都是“4 up”——在网格中显示 4 个数据 block 。我打算使用滑动手势在该应用程序的一组逻辑屏幕之间移动。
- 4up(屏幕 A)
- 4up(屏幕 B)
- 4up(屏幕 C) 等等
现在我有一个单个 Activity ,一个包含“屏幕”(标题和一种数据类型)的数组列表和一个单个布局文件,其中包含 4up编码到其中的元素。我使用单击处理程序移动到数组列表中的下一个位置并重新绘制屏幕上的元素。数据元素本身正在从网络连接中读取,并在进入时刷新到屏幕上。这部分效果很好。
我想使用所有屏幕转换以及我的手势,使其看起来像这些屏幕的水平滚动列表,但只有其中 1 个...所以我会绘制屏幕 1,向右滑动以到达屏幕2、向右滑动进入屏幕3等
应用程序的进展如下所示(伪代码):
onCreate{
get handles to the elements of the layout
setupScreenData() - this sets up the arraylist of "screens"
run the network listener() - this starts a thread and connects to the activity via a Handler
}
//this happens when I get data from the network
handleMessage{
//this combines data in the screens array with data sent back from the network
refreshScreenData()
}
onClick{
increment the pointer in the screen array
}
最佳答案
事实证明,逻辑屏幕被称为“fragment ”,您需要使用 View 页面来获取我正在寻找的行为。这是一篇 SO 帖子,描述了我目前使用的方向:
How to implement a ViewPager with different Fragments / Layouts
关于java - 逻辑 fragment 与实际 fragment ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26075540/