问题
I have one ImageView
and I want to set as background image in image View
How can I do that?
回答1:
First put your image in res/drawable folder with desired resolution( drawable-hdpi, drawable-ldpi, drawable-mdpi) folder.
Then try like this:
<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>
回答2:
Try like this:
Copy your image file to /res/drawable directory
your layout should look like:
<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>
来源:https://stackoverflow.com/questions/20812851/how-to-set-background-and-save-image-in-imageview