简体   繁体   中英

background on emulator being stretched

I have a background on my android app with is a png image. It is 800 x 480 px in size. It is being stretched width wise and hence does not look as I intend it to. As the image is actually the background of the app and not just an imageView I was unable to use the android:scaleType="centerCrop" to get the image to scale equally.

I need the image to fill the background equally.

I have also tried using NinePatch drawable but the results were not good at all on this - The image became blurred or was OK when being stretched vertically but not width wise.

图像前在模拟器上看到的图像后

Here is my XML code:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:background="@drawable/menu"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" 

Is there any other command I can use to get the background to display correctly?

to resolve this use draw9patch

android-sdk/tools/draw9patch

https://developer.android.com/tools/help/draw9patch.html

use imageview

<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/your_image"
android:scaleType="fitCenter"
/>

check this also Link

ImageView.ScaleType     CENTER_CROP

Scale the image uniformly (maintain the image's aspect ratio) so that both dimensions (width and height) of the image will be equal to or larger than the corresponding dimension of the view (minus padding). 

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