例如文字檔
使用底下code得到檔案輸入InputStream物件
getResources.getAssets().open("text.txt")"
一般資源檔案放在res目錄
包含圖片、聲音、版面配置等等
圖片資源檔範例:
Step1: 將圖片放在res/drawable-mdpi目錄下
兩種方式使用圖片
1. 靜態配置:
在activity_main.xml中
<ImageView
android:id="@+id/imageView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:src="@drawable/img"
/>
@drawable/img中的img為檔案名稱2. 動態配置:
在程式原始碼中
ImageView imageView = new ImageView(this);
imageView.setImageBitmap(
BitmapFactory.decodeResource(getResources(),R.drawable.img));
this.setContentView(imageView);
R.drawable.img中的img為檔案名稱
---
參考書籍: 學會Android 應用開發的18堂關鍵基礎課程(博客來、讀冊生活)
沒有留言:
張貼留言