安卓操作系统不会重新调整大小与同等规模的图像 [英] Android: OS not re-sizing images with the same scale
问题描述
我对Android操作系统是如何处理调整对我的一个应用程序的困扰。基本上我有一个背景图像是480×800(所以480像素宽),并且进入底部,还480像素的图像宽。
在Galaxy S(480x800的屏幕)一切正常,如下图所示:
在银河S3(720x1280),然而,背景是越来越拉伸到720像素宽,但在底部的图像仅640像素宽,如下所示:
我试图创建一个xhdpi文件夹640x960的图像,但同样的事情发生(背景拉伸到720像素,图片仅640像素)。我也试图与ScaleType游戏,但至今没有运气。
有谁知道为什么操作系统将重新大小的两幅图像具有不同的规模,以及如何解决它?
下面是XML:
<?XML版本=1.0编码=UTF-8&GT?;
< LinearLayout中的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT
机器人:方向=垂直
机器人:背景=@绘制/ BG> <按钮
机器人:ID =@ + ID /按钮1
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:背景=@绘制/ significados
机器人:layout_gravity =中心
机器人:layout_marginTop =216dp
安卓的onClick =goToSignificados
/> <按钮
机器人:ID =@ + ID /按钮2
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:背景=@绘制/排行榜
机器人:layout_gravity =中心
安卓的onClick =goToRanking
/> <按钮
机器人:ID =@ + ID /按钮3
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:背景=@绘制/ engracados
机器人:layout_gravity =中心
安卓的onClick =goToEngracados
/> < ImageView的
机器人:ID =@ + ID / IV1
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_gravity =中心
机器人:layout_marginTop =60dp
机器人:可点击=真
机器人:contentDescription =@字符串/图像
安卓的onClick =goToMarket
机器人:SRC =@绘制/ GOOGLEPLAY/>< / LinearLayout中>
您必须张贴您的XML的,以获得更具体的答案,但基本上所有的视图可以处理图像缩放不同。
在你的榜样,
您可以让你的按钮使用宽度=匹配父母舒展的所有道路。
背景,将默认拉伸,也可以平铺。
按钮将有背景大小的尺寸最小,但将延伸在需要时(按钮有太多的文字)
作为一个方面说明,你不应该依赖于图像的确切像素。你应该看看九宫或使瓷砖的背景,并确保您充分利用之类的东西巅峰父母,重力等。
I am troubled by how the Android OS is handling resizing on an app of mine. Basically I have a background image that is 480x800 (so 480px wide) and an image that goes at the bottom, also 480px wide.
On the Galaxy S (480x800 screen) everything looks fine, as shown below:
On the Galaxy S3 (720x1280), however, the background is getting stretched to 720px wide but the image at the bottom only to 640px wide, as shown below:
I tried to create a xhdpi folder with 640x960 images, but same thing happens (background stretched to 720px, image only to 640px). I also tried to play with "ScaleType", but no luck so far.
Does anyone know why the OS would re-size the two images with a different scale, and how to fix it?
Here's the XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="@drawable/bg" >
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/significados"
android:layout_gravity="center"
android:layout_marginTop="216dp"
android:onClick="goToSignificados"
/>
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/ranking"
android:layout_gravity="center"
android:onClick="goToRanking"
/>
<Button
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/engracados"
android:layout_gravity="center"
android:onClick="goToEngracados"
/>
<ImageView
android:id="@+id/iv1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="60dp"
android:clickable="true"
android:contentDescription="@string/image"
android:onClick="goToMarket"
android:src="@drawable/googleplay" />
</LinearLayout>
You'll have to post your XMLs to get a more specific answer but basically all "Views" may handle image scaling differently.
In your example,
You can make your button stretch all the way by using width = match-parent.
"Backgrounds" will stretch by default, but can also tile. "Buttons" will have a min size of the background size but will stretch when needed (button has too much text)
As a side note, you shouldn't depend on the exact pixels of the images. You should look into nine-patch or making tiled backgrounds and make sure you take advantage of things like "match-parent, gravity, etc."
这篇关于安卓操作系统不会重新调整大小与同等规模的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!