繁体   English   中英

模拟器被拉伸的背景

[英]background on emulator being stretched

我的Android应用程式背景为png图像。 尺寸为800 x 480像素。 它在宽度方向上被拉伸,因此看起来不像我预期的那样。 由于图像实际上是应用程序的背景,而不仅仅是imageView,因此我无法使用android:scaleType =“ centerCrop”来使图像平均缩放。

我需要图像平均填充背景。

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

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

这是我的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" 

我还有其他命令可以用来正确显示背景吗?

解决这个问题,使用draw9patch

android-sdk / tools / draw9patch

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

使用imageview

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

还要检查此链接

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