Reputation: 499
I want to place an image at the right of the screen width minus 20 dp on a android device.
The pseudo code for this could be:
Parts 1 & 3 are clear, but the second part I guess is tough & is where I need some help.
Upvotes: 0
Views: 154
Reputation: 5151
You can use a RelativeLayout
as a container. Set android:layout_alignParentRight="true"
and android:layout_marginRight="20dp"
on an ImageView
within this layout.
You can get more information here.
Upvotes: 2
Reputation: 68167
Yes, you can get it with xml too:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="right"
android:layout_marginRight="20dp"
android:orientation="vertical" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/icon" />
</LinearLayout>
Note that android:layout_marginRight="20dp"
sets padding from right
Upvotes: 0
Reputation: 419
My understanding is that you will need to do this in a Java class where you get the dimensions of the window, do your calculations and then set the position of the image within the onCreate()
Method.
Upvotes: 0