如何在imageView中设置背景并保存图像?

时间:2013-12-28 09:15:43

标签: android image background imageview

我有一个ImageView,我想在图片视图中设置为背景图片

我该怎么做?

2 个答案:

答案 0 :(得分:1)

首先将图像放在具有所需分辨率(drawable-hdpi,drawable-ldpi,drawable-mdpi)文件夹的res / drawable文件夹中。

然后尝试这样:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"    
    tools:context=".MainActivity" >

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:background="@drawable/bg"/>
</RelativeLayout>

答案 1 :(得分:0)

试试这样:

  

将您的图像文件复制到/ res / drawable目录

您的布局应如下所示:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/bg"
    tools:context=".MainActivity" >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:text="@string/hello_world"/>
</RelativeLayout>
相关问题