简体   繁体   English

模拟器被拉伸的背景

[英]background on emulator being stretched

I have a background on my android app with is a png image. 我的Android应用程式背景为png图像。 It is 800 x 480 px in size. 尺寸为800 x 480像素。 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. 由于图像实际上是应用程序的背景,而不仅仅是imageView,因此我无法使用android:scaleType =“ centerCrop”来使图像平均缩放。

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. 我也尝试过使用NinePatch drawable,但是在此上的结果一点都不好-垂直拉伸但宽度方向拉伸时图像变得模糊或可以。

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

Here is my XML code: 这是我的XML代码:

<?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 解决这个问题,使用draw9patch

android-sdk/tools/draw9patch android-sdk / tools / draw9patch

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

use imageview 使用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). 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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