当前位置: 动力学知识库 > 问答 > 编程问答 >

Creating a background image for android apps

问题描述:

I am creating android app.

My phone is Galays S3

I created a png file which is also a background of the app with size W: 680px - H: 120pdx.

it fits fine. But when I run that on emulator the image is stretched and only see about 50% of the background image..

I called in the background image by the following code..

<ImageView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:src="@drawable/bg"

android:scaleType="matrix" />

all the drawlble folders such as hdpi , mdpi , xhdpi, xxhdpi has the same file with same respolution and size.. bg.png . size W: 680px - H: 120pdx.

网友答案:

It really depends on what you want to achieve but it looks like you should use scaletype="centercrop". You will get your image full screen but cropped. If you want it full screen and streched in lower resolution then use fitcenter.

It's really difficult to know exactly what you have in mind as you should explain :

  • what you want to happen on lower densities
  • what happens on devices with a different ratio than your image.

Other options : http://developer.android.com/reference/android/widget/ImageView.html#attr_android:scaleType

网友答案:

If you don't want to stretch it you can use android:scaleType="centerCrop"

Actually, if the devices are different, you have to choose between stretch it or not display all of it.

You can find all the possible values of scaleType here

网友答案:

You need to make sure that your Android emulator's display resolution the same as that of the Galaxy S3 phone you have. If it's not, you need to scale your image to fit your emulator display. Also, if you want the ImageView to stretch to fill the display, you need to use "match_parent" instead of "wrap_content". Be aware that this will affect image quality.

分享给朋友:
您可能感兴趣的文章:
随机阅读: