为什么图像尺寸更大?

时间:2012-03-04 11:14:24

标签: android layout

我正在使用这样的布局:

<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屏幕宽度为600px,但在推出的应用程序中,我看到图像几乎占据了所有屏幕宽度,大约是500像素

我在哪里弄错了?

解决
通过设置

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

并将图片放到drawable-hdpi

3 个答案:

答案 0 :(得分:2)

  1. 正如你所说的那样是针对galaxy tab所以它是在drawable-hdpi下进行的。所以用photoshop或其他东西改变图像的分辨率并把它放在drawable-hdpi中。
  2. 并尝试使用 android:layout_width =“wrap_content”。而不是 android:layout_width =“fil_parent”

答案 1 :(得分:1)

我建议您好好阅读documentation。如果您已将图像放在drawable-mdpi文件夹中,则在高密度屏幕中,图像的大小将为1.5倍。您必须为不同的屏幕密度提供不同的图像分辨率。

答案 2 :(得分:1)

您在背景中设置图片,android:background标记使用9张图片。因此,您的背景始终延伸到视图的宽度和高度。您的布局宽度设置为fill_parent,因此图片宽度也为fill_parent。 解决方案可能是使用.9.png扩展名制作您正在使用的png的9补丁图像。 阅读here drawing 9 patch images - developer.android.com/guide/developing/tools/draw9patch.html