Posted on 2009-11-02 14:31
瘋狂 閱讀(1151)
評論(0) 編輯 收藏 所屬分類:
android
有兩種方式
首先找一個png的圖片放在res/drawable文件架下,文件名和擴展名全部用小寫(注意),我的文件名稱:android.png
1.code方式:
ImageView imageView = new ImageView(this);
imageView.setImageResource(R.drawable.android);//R.drawable.android后面的android是你的圖片文件名
setContentView(imageView);
2,xm方式:
修改main.xml
添加:
<ImageView
android:id="@+id/imageview"
android:layout_height="wrap_content" //圖片原來的size 如果用fill_parent 就會拉伸
android:layout_width="wrap_content"
android:src="@drawable/android" //注意文件名
/>
代碼加入:setContentView(R.layout.main);即可
運行:
