以一個(gè)簡(jiǎn)單的圖片瀏覽器實(shí)例說(shuō)明
成都創(chuàng)新互聯(lián)公司是專業(yè)的山陽(yáng)網(wǎng)站建設(shè)公司,山陽(yáng)接單;提供成都做網(wǎng)站、成都網(wǎng)站設(shè)計(jì)、成都外貿(mào)網(wǎng)站建設(shè),網(wǎng)頁(yè)設(shè)計(jì),網(wǎng)站設(shè)計(jì),建網(wǎng)站,PHP網(wǎng)站建設(shè)等專業(yè)做網(wǎng)站服務(wù);采用PHP框架,可快速的進(jìn)行山陽(yáng)網(wǎng)站開發(fā)網(wǎng)頁(yè)制作和功能擴(kuò)展;專業(yè)做搜索引擎喜愛的網(wǎng)站,專業(yè)的做網(wǎng)站團(tuán)隊(duì),希望更多企業(yè)前來(lái)合作!
新建工程后:
在activit_main.xml中添加代碼:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/main" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > </LinearLayout>
在java中添加代碼:
public class MainActivity extends Activity { int[] p_w_picpath = new int[] { R.drawable.p1, R.drawable.p2, R.drawable.p3, R.drawable.p4 }; ImageView myp_w_picpath; int curImage = 0; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); LinearLayout layout = (LinearLayout)this.findViewById(R.id.main); myp_w_picpath = new ImageView(this); layout.addView(myp_w_picpath); myp_w_picpath.setImageResource(p_w_picpath[0]); myp_w_picpath.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { // TODO Auto-generated method stub myp_w_picpath.setImageResource(p_w_picpath[++curImage%p_w_picpath.length]); } }); }
在Android中,每一個(gè)組件的性質(zhì)可以在.xml中定義,同時(shí)每個(gè)性質(zhì)都有對(duì)應(yīng)的java方法
注意:以上代碼中 使用java代碼添加新的組件,可把聲明寫在類中,但是他必須被賦值為一個(gè)new在onCreate()內(nèi)部的對(duì)象,否則程序會(huì)出錯(cuò),究其原因是因?yàn)樵趈ava中添加組件的時(shí)候必須初始化的時(shí)候加入?yún)?shù)(this)
當(dāng)前文章:Android使用xml和java混合編寫ui
網(wǎng)頁(yè)URL:http://www.chinadenli.net/article48/iijshp.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站收錄、網(wǎng)站營(yíng)銷、企業(yè)建站、網(wǎng)頁(yè)設(shè)計(jì)公司、面包屑導(dǎo)航、品牌網(wǎng)站制作
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)