亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如下程序,有人知道是怎么回事嗎?

如下程序,有人知道是怎么回事嗎?

嗶嗶one 2022-10-07 19:15:46
@Overridepublic void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);requestWindowFeature(Window.FEATURE_NO_TITLE);//去掉標題欄setContentView(R.layout.wk_main);/*這里背景圖片設置成功了*/layout=(LinearLayout) findViewById(R.id.layout1);resources = getResources();btnDrawable = resources.getDrawable(R.drawable.app2_0);layout.setBackgroundDrawable(btnDrawable);/*到這里 就設置失敗*/btnDrawable = resources.getDrawable(R.drawable.app1_1);layout.setBackgroundDrawable(btnDrawable);<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:id="@+id/layout1"android:layout_width="fill_parent"android:layout_height="fill_parent"android:orientation="vertical" ><LinearLayoutandroid:layout_width="fill_parent"android:layout_height="match_parent"android:orientation="horizontal"android:layout_weight="1">
查看完整描述

2 回答

?
飲歌長嘯

TA貢獻1951條經驗 獲得超3個贊

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

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

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

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

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

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

[java] view plaincopy
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 plaincopy
imageView1.setImageDrawable(imageView2.getDrawable());


查看完整回答
反對 回復 2022-10-12
?
MYYA

TA貢獻1868條經驗 獲得超4個贊

代碼如下:
LinearLayout?temp=(LinearLayout)findViewById(R.id.LinearLayout的id);
Drawable?d=Drawable.createFromPath(圖片路徑);
temp.setBackgroundDrawable(d);

查看完整回答
反對 回復 2022-10-12
  • 2 回答
  • 0 關注
  • 137 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號