How to Set background and save image in imageView? [closed]

我怕爱的太早我们不能终老 提交于 2019-12-14 03:35:05

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!