0

I know I can use margins to do that but I am getting some problems when objects are near edge of the screen. In this case android tries to fit all contents of view into screen which is something I don't want. For example if I give 200 width to a view and 100px of this is outside the screen it fits it to 100 px.

How can I avoid this?

Also why AbsoluteLayout is deprecated? I am currently working with it and it works but I wonder if people will throw stones at me

  • 1
    `why AbsoluteLayout is deprecated` - because any layout you build with it can only work for one screen size, unless you start measuring the screen in code and adjusting the positions of the child views programatically. Besides, there is NOTHING that `AbsoluteLayout` can do that you cannot achieve in a more generic way. To help with your problem, please edit your question and paste the layout XML. – Simon Nov 04 '13 at 21:09
  • 1
    Could you please post your layout and tell us exactly which result you'd like to get? In any case, please do not use AbsoluteLayout and px units. – fasteque Nov 04 '13 at 21:09

3 Answers3

0

Without seeing your actual layout, it sounds like you want to have content that is offscreen. If you would like the user to be able to see that content, you could use a scroll view. That way, when you start your activity, your stuff will show up as you've laid out, with any overflow offscreen, and then the user can scroll over to it as desired.

            <HorizontalScrollView
                    android:layout_width="match_parent"
                    android:layout_height="match_parent">
                <LinearLayout
                        android:layout_width="wrap_content"
                        android:layout_height="match_parent"
                        android:orientation="horizontal">

                        <!--your stuff here -->

                </LinearLayout>
            </HorizontalScrollView>

Otherwise, if it's an image, there are various cropping and alignment options that could cover what you want.

GLee
  • 5,003
  • 5
  • 35
  • 39
0

Use RelativeLayout. Then just perform a simple check when adding View to RelativeLayout. For instance remember the last lastX & lastY location of added View and then check whether lastX + newView.width() <= RelativeLayout.width(). True -> add it, False -> set Y coordinate of newView to something like lastY + HEIGHT + BOTTOM_MARGIN and lastX back to 0

Husky
  • 1,451
  • 4
  • 19
  • 35
0

In the end I just added some negative paddings to my relative layout. Thanks to these paddings, views does not try to fit themselves into screen