Android 如何在imageView中设置背景和保存图像?
我有一个Android 如何在imageView中设置背景和保存图像?,android,image,background,imageview,Android,Image,Background,Imageview,我有一个ImageView,我想在图像视图中设置为背景图像 我该怎么做呢?试着这样做: <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_pare
ImageView
,我想在图像视图中设置为背景图像
我该怎么做呢?试着这样做:
<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>
将图像文件复制到/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>
首先将图像以所需分辨率(可绘制hdpi、可绘制ldpi、可绘制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>
wt的意思是设置背景手机可能的重复