I've a imageView in my layout which serves as a background which doesn't scale. But I need to have my image in the topright corner of the screen. I now have my image in the top left corner of the screen. This is my xml for the imageview:
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentRight="true"
android:src="@drawable/achtergrond"
android:scaleType="fitCenter" />
I also tried to put it in a linearlayout which has gravity="top|right" but that doesn't remove the white space around the picture because it's with the match_parent sizes. I also need to keep the scale of the picture, so I can't do fill_parent.
I hope someone can help me with this!
Maybe add
android:adjustViewBounds="true"
to your ImageView
? I had a similar problem.
The following layout will position your image (or any other view) at the top right corner of the screen. Check comments below code block for more details.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true" />
</RelativeLayout>
The important parts are the wrapping RelativeLayout
and the layout_alignParentRight
and layout_alignParentTop
set to true on the view itself.
This won't wrap your complete view yet since it's all wrap_content
. You can use different size resources per screen type or work with different layout_width
and layout_height
and then use the scaleType
property as you whish (probably fitXY
to scale image to match the view).
Don't use a LinearLayout
if not necessary. Documentation on RelativeLayout
can be found here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With