2011-04-29 23 views
0

我有一個應用程序,我想更改代碼中的位圖源。 我已經得到了主要佈局:Android更改應用程序內的位圖src

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:paddingLeft="5px" 
    android:paddingRight="5px" 
    android:paddingTop="5px" 
    android:background="@drawable/my_image" 
> 
... 
</RelativeLayout> 

這裏是背景中的XML:

<bitmap 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:dither="true" 
android:gravity="bottom|right" 
android:src="@drawable/image" /> 

現在,當有源,然後它工作的內部圖像的名字,但我想當我在上一課中選擇另一個列表項時更改它。我知道有getResources,但我真的不知道如何用位圖解決它。當有字符串時,這很容易,但這樣我就不知道該去哪裏。

回答

0

將位圖的xml放在drawable文件夾中,然後將背景資源設置爲android:background =「@ drawable/bitmap」(位圖是可繪製的xml的名稱)。 或給出相對佈局的id並使用Relativelayout.setBackgroundResource()方法。