2

My activity looks like this

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

The View Group that fills the screen is a child of a RelativeLayout that RelativeLayout fills the screen with fill_parent and layout_below header and layout_above footer. The ViewGroup under that RelativeLayout is set to the same width and height of the RelativeLayout at runtime.

The reason it is set the same height at runtime is because this view group can be dragged over to the left with a finger (similar to the Android home screen) If I drag it to the left it is fine. But if I drag it to the right my fill_parent dimensions get messed up.

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

The way I am doing the positioning is by setting the left margin of the ViewGroup which will shift it right (or setting it negative to shift it left)

Why I can't use HorizontalScrollView.

Here is a top view of the android

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

I am planning for the user to be able to go next/previous by dragging the screen right and left. If the user drags the screen a little and he/she does it slowly

        ' previous ' current  '   next   ' 
                |          |

Then the screens should animate back in place

     ' previous ' current  '   next   ' 
                |          |

If the user does it quickly

              ' previous ' current  '   next   ' 
                |          |

Then the screens should animate the rest of the way

                ' previous ' current  '   next   ' 
                |          |

Previous should become the new current and we should have a new previous

     ' previous ' current  '   next   ' 
                |          |

I used a scrollview I would be doing something like this

     ' previous ' current  '   next   ' 
     |          |

Now there is no room for a new previous unless I jump the scrolling

     ' previous ' current  '   next   ' 
                |          |

which sounds even worse to me.

So my options are

  • AbsoluteLayout (deprecated / don't use it)
  • RelativeLayout.LayoutParams.setMargins (See below. This is what I am doing now)
  • Write my own LayoutManager (Sounds easier than it is)
  • Draw the pixels to the screen instead of using Views (DirectDraw or OpenGL)
  • HorizontalScrollView
Community
  • 1
  • 1
700 Software
  • 85,281
  • 83
  • 234
  • 341

1 Answers1

5

If you set a positive left margin then you should also set a negative right margin. This allows the ViewGroup to continue off the edge of the screen on the right hand side.

700 Software
  • 85,281
  • 83
  • 234
  • 341