Is there a way to offset a view from center? Is there a way to offset a view from center? android android

Is there a way to offset a view from center?


Depending on the screen size of the target device, padding by X dp might move it more than just a fifth of the height.

You might have to code this movement yourself. However, nothing prevents you from doing:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@drawable/background" android:padding="20dp" ><Viewandroid:id="@+id/fakeView"android:layout_width="10dp"android:layout_height="10dp"android:layout_centerInParent="true"android:background="#FFAABB" /><ImageButtonandroid:id="@+id/flashlight_button"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_centerHorizontal="true"android:layout_above="@+id/fakeView"android:marginBottom="50dp"android:background="@null"android:contentDescription="@string/flashlight_button_description"android:src="@drawable/freeml_bright" /></RelativeLayout>


Don't use margin, use padding (top), like so:

<Viewandroid:id="@+id/fakeView"android:layout_width="10dp"android:layout_height="10dp"android:layout_centerInParent="true"android:paddingTop="80dp"android:background="#FFAABB" />

That should work, though I've not tested it!


try using attribute android:layout_toLeftOf="@+id/fakeView"