2016-07-22 49 views
-2

所以,我對Android編程完全陌生。我希望我的ImageView根據編碼函數的結果更改其圖像。ImageView功能

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

    <ImageView 
     android:id="@+id/logo" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_gravity="top" 
    android:src="@drawable/logo"/> 

    <ImageView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_below="@id/logo" 
     android:src="@drawable/server"/> 

    <ImageView 
     android:id="@+id/status" 
     android:layout_width="wrap_content" 
     android:layout_height="match_parent"/> 

那麼,我應該怎麼寫才能讓ImageView自己做些什麼(我的意思是「狀態」ImageView,它是最後一個)?沒有點擊或按下。

+0

就叫'imageView.setImageBitmap()'或'imageView.setImageResource ()' –

+0

你想做什麼?一點也不清楚。 – Drv

+0

「無法點擊或按下」意味着您需要從ImageView的開始處設置圖像(直接在XML中使用android:src =「@ drawable/image」)或者您想要代碼行imageView.setImageBitmap(...)/imageView.setImageResource(...)或者你想讓它在一段時間後自動發生,或者當你的應用程序中的其他任何地方發生什麼事情時你想讓它改變嗎? – LuigiPower

回答

0

1)右鍵單擊可繪製文件夾,然後選擇添加現有文件,然後從計算機中選擇一個圖像。

2)然後在你的XAML文件中加入這一行你imageview的下:機器人:背景= 「@繪製/ NameOfThePictureThatYouJustAddedToTheDrawableFolder」

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:background="@drawable/bg" > <ImageView android:id="@+id/logo" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="top" android:src="@drawable/logo"/> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@id/logo" android:src="@drawable/server"/> <ImageView android:id="@+id/status" android:layout_width="wrap_content" android:layout_height="match_parent" android:background="@drawable/NameOfThePictureThatYouJustAddedToTheDrawableFolder" />