2012-03-04 123 views
1

我使用这样的布局:为什么图像的尺寸更大?

<LinearLayout 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:background="@drawable/logo" 
    android:orientation="horizontal" > 

drawable/logo.xml

<bitmap xmlns:android="http://schemas.android.com/apk/res/android" 
    android:src="@drawable/login_logo" 
    android:gravity="center" /> 

drawable/login_logo.png有280个像素宽度,我Galaxy Tab的屏幕宽度为600像素,但在推出的应用程序,我看到图片后几乎所有的屏幕宽度,它是大约500px

我在哪里犯错?

解决
通过设置

<uses-sdk android:minSdkVersion="4" /> 

,并把图像drawable-hdpi

回答

1

您正在背景中设置图片,并且android:background标签使用9个补丁图像。所以你的背景总是延伸到视图的宽度和高度。您的布局宽度设置为fill_parent,因此图片宽度也是fill_parent。 解决方案可能是使用.9.png扩展名创建您正在使用的png的9个补丁映像。 阅读heredrawing 9 patch images - developer.android.com/guide/developing/tools/draw9patch.html

+0

我试图使用9路图像,但也有同样的效果。 – 2012-03-04 11:35:20

+0

你把分数放在正确的位置吗?我的意思是,如果你想整个图像转换为非strechable你需要把点的长度和宽度 – noob 2012-03-04 11:39:52

+0

是啊,我已经添加了必要的拉伸区..但问题是设备放大每一个它的工作原理与 – 2012-03-04 11:42:02

1

我建议你有documentation的很好看。如果您将图像放在drawable-mdpi文件夹中,那么在高密度屏幕中,图像尺寸将显示为1.5倍。您将不得不为不同的屏幕密度提供不同的图像分辨率。

+0

我也试过把同样的图像放在'drawable-hdpi'中,但是效果相同。 – 2012-03-04 11:33:47

2
  1. 正如你说的是对的Galaxy Tab故drawable-hdpi.So在未来的变化的决议图像与Photoshop或东西,并把它放在drawable-hdpi里面。
  2. 并尝试使用android:layout_width =“wrap_content”。而不是android:layout_width =“fil_parent”