I am trying to set a image like background image in a layout (by xml or by code)
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/main_layout"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/my_image">
or
View myLayout= findViewById( R.id.main_layout);
myLayout.setBackgroundResource(R.drawable.my_image);
My problem is than android fix the image in the all background screen, resizing and modifying the image ratio.
How can I set a image, and that the image takes only the neccesary space? (without image resizing)
Without adding an ImageView
to the layout, if the image is smaller than the space, you can create an xml bitmap resource like the following, and use this in place of the original background image:
<?xml version="1.0" encoding="utf-8"?>
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
android:src="@drawable/background"
android:gravity="center"
/>
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