设置背景图像

时间:2011-07-12 20:06:03

标签: android

我想设置背景如下

enter image description here

但我得到这样的

enter image description here

当我将图像裁剪成一半时,我变得像这样(模糊)

enter image description here

原始图片是 enter image description here

请指导我如何设置原始

xml文件 网格xml

<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/GridItem"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:gravity="center_horizontal"
    >



    <ImageView
        android:id="@+id/grid_item_image"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">
    </ImageView>

    <TextView
        android:id="@+id/grid_item_text"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="TextView"
        android:gravity="center_horizontal"
        android:textColor="#ffffff">
    </TextView>

</LinearLayout>

main xml

<?xml version="1.0" encoding="utf-8"?>
<GridView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/MyGrid"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:padding="5dp"
    android:verticalSpacing="5dp"
    android:horizontalSpacing="10dp"
    android:numColumns="auto_fit"
    android:columnWidth="80dp"
    android:stretchMode="columnWidth"
    android:gravity="center_horizontal"

        android:scaleType="fitXY"   
     android:background="@drawable/backimage"
 >
</GridView>

我当时认为这可能是由于错误的xml放置所以我也试过没有gridlayout但到目前为止没有运气。

现在我为这样的图像创建了多个文件夹 enter image description here 并在清单文件中添加这些行

<supports-screens  
     android:smallScreens="false"       android:normalScreens="true"
      android:largeScreens="true"
      android:anyDensity="true" />

请指导还有什么需要做的

谢谢

4 个答案:

答案 0 :(得分:3)

事实上,最好的方法是将原始图片重新缩放到屏幕尺寸。你想要的图片是原件的裁剪插图。 (右边的红色几乎消失了)。所以一种方法是改变边距。以下数字取决于您的屏幕分辨率。

enter image description here

这是Main.xml:

<?xml version="1.0" encoding="utf-8"?>

android:background="@drawable/love"
android:id="@+id/imageView1"



android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="-190px"
android:layout_marginRight="-210px"
android:layout_marginTop="-20px"
android:layout_marginBottom="-200px"

android:layout_gravity="fill_horizontal"
  

答案 1 :(得分:1)

你放在哪里:

 android:scaleType="fitXY" 

我认为你应该使用类似维持图像宽高比的东西

android:scaleType="centerInside"

答案 2 :(得分:1)

你面临着几个问题。

  1. 将比例类型更改为CENTER_INSIDE。我想这可能就是你想要的那个。在此处查看其他人:ImageView.ScaleType

  2. 模糊可能是由几件事引起的。我会为不同的屏幕密度放置不同的drawable。请参阅Supporting multiple screens

答案 3 :(得分:0)

您是否尝试将其强制为32位?

在你的onCreate中:

getWindow()setFormat(PixelFormat.RGBA_8888);

相关问题