Android:有没有办法让fill_parent不缩小以适合父母的父级?

Bry*_*eld 2 layout android dimensions

我的活动看起来像这样

| header           |
|------------------|
|  ViewGroup       |
|  that fills      |
|  the screen      |
|                  |
|     centered     |
|      button      |
|                  |
|------------------|
| footer           |
Run Code Online (Sandbox Code Playgroud)

填充屏幕的视图组是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           |
Run Code Online (Sandbox Code Playgroud)

我正在进行定位的方法是设置ViewGroup的左边距,将其向右移动(或将其设置为负值以将其向左移动)

为什么我不能使用HorizontalScrollView.

这是android的顶视图

     ' previous ' current  '   next   ' # Three panes that can be dragged to switch between
                |          | # The android screen bounderies
Run Code Online (Sandbox Code Playgroud)

我正在计划用户能够通过左右拖动屏幕来进行下一个/上一个.如果用户拖动屏幕一点点,他/她慢慢地

        ' previous ' current  '   next   ' 
                |          |
Run Code Online (Sandbox Code Playgroud)

然后屏幕应该动画回原位

     ' previous ' current  '   next   ' 
                |          |
Run Code Online (Sandbox Code Playgroud)

如果用户快速完成

              ' previous ' current  '   next   ' 
                |          |
Run Code Online (Sandbox Code Playgroud)

然后屏幕应该为剩下的方式设置动画

                ' previous ' current  '   next   ' 
                |          |
Run Code Online (Sandbox Code Playgroud)

以前应该成为新的潮流,我们应该有一个新的前一个

     ' previous ' current  '   next   ' 
                |          |
Run Code Online (Sandbox Code Playgroud)

我用了一个scrollview,我会做这样的事情

     ' previous ' current  '   next   ' 
     |          |
Run Code Online (Sandbox Code Playgroud)

除非我跳过滚动,否则现在没有新的前一个空间了

     ' previous ' current  '   next   ' 
                |          |
Run Code Online (Sandbox Code Playgroud)

这对我来说听起来更糟糕.

所以我的选择是

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

Bry*_*eld 5

如果设置正左边距,则还应设置负右边距.这允许ViewGroup继续离开右侧屏幕的边缘.