2

我的活动看起来像这样

| header           |
|------------------|
|  ViewGroup       |
|  that fills      |
|  the screen      |
|                  |
|     centered     |
|      button      |
|                  |
|------------------|
| footer           |

填充屏幕的 View Group 是 RelativeLayout 的子项,RelativeLayout 使用 fill_parent 和 layout_below 页眉和 layout_above 页脚填充屏幕。该RelativeLayout 下的ViewGroup 在运行时设置为与RelativeLayout 相同的宽度和高度。

在运行时将其设置为相同高度的原因是因为可以用手指将这个视图组拖到左侧(类似于 Android 主屏幕)如果我将它拖到左侧就可以了。但是如果我把它拖到右边,我的 fill_parent 尺寸就会搞砸。

| header           |
|------------------|
|     '  ViewGroup |     ' 
|     '  that fills|     '
|     '  the screen|     '
|     '            |     '
|     '  centered  | <-- button not centered. It is only centered on the visible area, not the whole thing
|     '   button   |     '
|     '            |     '
|     '            |     '
|------------------|
| footer           |

我进行定位的方式是设置 ViewGroup 的左边距,它将向右移动(或将其设置为负向左移动)

为什么我不能用HorizontalScrollView

这是android的顶视图

     ' previous ' current  '   next   ' # Three panes that can be dragged to switch between
                |          | # The android screen bounderies

我计划让用户能够通过左右拖动屏幕来进入下一个/上一个。如果用户稍微拖动屏幕并且他/她拖得很慢

        ' previous ' current  '   next   ' 
                |          |

然后屏幕应该动画回到原位

     ' previous ' current  '   next   ' 
                |          |

如果用户快速完成

              ' previous ' current  '   next   ' 
                |          |

然后屏幕应该动画其余的方式

                ' previous ' current  '   next   ' 
                |          |

以前的应该成为新的现在,我们应该有一个新的以前

     ' previous ' current  '   next   ' 
                |          |

我使用了滚动视图我会做这样的事情

     ' previous ' current  '   next   ' 
     |          |

现在没有空间容纳新的前一个,除非我跳过滚动

     ' previous ' current  '   next   ' 
                |          |

这对我来说听起来更糟。

所以我的选择是

  • AbsoluteLayout(已弃用/不要使用它)
  • RelativeLayout.LayoutParams.setMargins(见下文。这就是我现在正在做的)
  • 自己写LayoutManager(听起来比实际容易)
  • 将像素绘制到屏幕上,而不是使用Views(DirectDraw 或 OpenGL)
  • HorizontalScrollView
4

1 回答 1

5

如果你设置一个正的左边距,那么你也应该设置一个负的右边距。这允许 ViewGroup 继续离开屏幕右侧的边缘。

于 2011-01-21T03:51:12.003 回答