I want that when I set margin bottom, which makes part of the view go out of the screen / not visible, the whole layout shifts to the top, looking “the same” – means, not re-arranging the views inside.
But when I set the margin, in this simplified example case, to container shrinks or the layout inside moves to the bottom. Here are pictures to illustrate:
Before setting margin:

After setting 200dip margin bottom:

This is the XML:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="400dip"
android:background="#ff0000"
android:gravity="center"
android:layout_marginBottom="200dip"
>
<View
android:layout_width="fill_parent"
android:layout_height="200dip"
android:background="#00ff00"
/>
</LinearLayout>
<Button
android:id="test"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
android:text="@string/hello_world"
tools:context=".MainActivity" />
</RelativeLayout>
What can I do to avoid this?
To achieve that, try setting a negative top-margin top the view you want to move up.