當前位置:首頁 » 安卓系統 » 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元素。

熱點內容
unity3d腳本打包 發布:2025-07-03 21:36:05 瀏覽:862
伺服器獨享寬頻怎麼樣 發布:2025-07-03 21:35:58 瀏覽:836
重慶哪裡有安卓手機專賣店 發布:2025-07-03 21:21:42 瀏覽:378
上傳ftp亂碼linux 發布:2025-07-03 21:20:26 瀏覽:332
多線程下載java 發布:2025-07-03 21:15:30 瀏覽:715
電腦做伺服器應該什麼配置 發布:2025-07-03 21:15:18 瀏覽:687
查看防火牆linux 發布:2025-07-03 21:07:10 瀏覽:85
phpjscss 發布:2025-07-03 20:43:01 瀏覽:215
p79選哪個配置 發布:2025-07-03 20:36:33 瀏覽:734
sql格式化日期函數 發布:2025-07-03 20:22:52 瀏覽:398