简体   繁体   中英

Android App background image fill height but not width

I am trying to add a background image to a view. The image is really wide and not so tall. It's 6400 x 480. I want the image to fill the android screen's height and keep it's aspect ratio. I cannot seem to get this to work.

<ImageView
    android:id="@+id/background"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/background"
    android:scaleType="fitStart"
    android:layout_alignParentBottom="true" />

Keep in mind I have tried all options with scaleType and it just doesn't give the desired effect. I want to be able to move the image to the left revealing the rest of the image later on.

Any advice, tips would be great! Maybe I am going about this the wrong way.

I ended up finding the solution myself. I created an XML file named background.xml in my drawables folder and placed this code in it:

<?xml version="1.0" encoding="utf-8"?>
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
    android:src="@drawable/background_image"
    android:tileMode="disabled" android:gravity="top|left|fill_vertical">
</bitmap>

Which created a bitmap object for use. I then add this android:background="@drawable/background" to my RelativeLayout tag in my main.xml.

Worked like a charm

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM