當前位置:首頁 » 安卓系統 » android設置圖片

android設置圖片

發布時間: 2024-11-22 15:39:26

① android設置背景圖片

教你如何設置背景圖片
xml文件設置背景圖片中:
任意一個控制項,button imageView 或layout,在其的xml屬性設置中,添加

[java] view plain
android:background="@drawable/bg"

即可實現設置其背景圖片為bg.
其中bg.bnp圖片存放在drawable目錄下。
drawable目錄下存放大小圖標共用的圖片。drawable-hdpi中存放240 WVGA800 的模擬器或板子用的圖片。drawable-mdpi存放對應的小圖片

[java] view plain
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/pic"/>

同樣,用src屬性,也可設置imageView的圖片為pic.png

java代碼中設置或更改一個控制項的背景圖片:

[java] view plain
Resources resources = getContext().getResources();
Drawable btnDrawable = resources.getDrawable(R.drawable.layout_bg);
layout.setBackgroundDrawable(btnDrawable);

程序中,動態修改layout的背景圖片,用setBackgroundDrawable()函數實現。設置其背景圖片為 layout_bg.png

修改imageView1的背景圖片為imageView2的背景圖片:
imageView2.getDrawable()可獲得圖片2的背景。值為Drawable類型
imageView1.setImageDrawable(drawable); 設置imageView1的背景圖片

即:

[java] view plain
imageView1.setImageDrawable(imageView2.getDrawable());

② android在布局中添加圖片

1、需要有一張圖片,可以使用任何圖片編輯器創建或編輯圖片,或者從互聯網下載。確保圖片的尺寸適合的應用程序。
2、將圖片文件放入Android項目的res/drawable目錄下。
3、打開想要添加圖片的布局文件(是XML文件),添加一個ImageView元素。

熱點內容
scratch少兒編程課程 發布:2025-04-16 17:11:44 瀏覽:628
榮耀x10從哪裡設置密碼 發布:2025-04-16 17:11:43 瀏覽:357
java從入門到精通視頻 發布:2025-04-16 17:11:43 瀏覽:76
php微信介面教程 發布:2025-04-16 17:07:30 瀏覽:300
android實現陰影 發布:2025-04-16 16:50:08 瀏覽:788
粉筆直播課緩存 發布:2025-04-16 16:31:21 瀏覽:338
機頂盒都有什麼配置 發布:2025-04-16 16:24:37 瀏覽:204
編寫手游反編譯都需要學習什麼 發布:2025-04-16 16:19:36 瀏覽:801
proteus編譯文件位置 發布:2025-04-16 16:18:44 瀏覽:357
土壓縮的本質 發布:2025-04-16 16:13:21 瀏覽:583