assets是存放本地支援的。主要放一些常用的資源。
這裡說說怎麼呼叫這個資料夾裡面的檔案。
(01)assets資料夾在專案中的位置
(02)獲取影象的方法/** * 從Assets中讀取圖片 * @param activity * @param fileName * @return */ public static Bitmap getImageFromAssetsFile(Activity activity,String fileName) { Bitmap image = null; AssetManager am = esources()ssets(); try { InputStream is = (fileName); image = deStream(is); e(); } catch (IOException e) { tStackTrace(); } return image; }這個地方要注意。(應為這是一種引用)來自Resources和Assets 中的檔案只可以讀取而不能進行寫的操作。
(03)這裡附加把圖片放到記憶體的方法
(04)獲取所有檔案的檔名/** * 獲取目錄下的所有檔案的檔名 * @param context * @return */ public static String[] get_img_list(Context context) { String[] list_image = null; try { //得到assets/build_img/目錄下的所有檔案的檔名,以便後面開啟操作時使用 return list_image = ssets()("processedimages"); } catch (IOException e1) { // TODO Auto-generated catch block tStackTrace(); } return list_image; }
(01)assets資料夾用於存放一些常用的資原始檔。(打包到應用程式的靜態檔案。)ASSETS支援任意深度的子目錄。(意思就是說,你可以在這個資料夾中寫多層資料夾的路徑。)這些檔案不會生成任何資源ID,必須使用/assets開始(不包含它)的相對路徑名。
(02)res/raw這個資料夾位置如圖。這個資料夾也會在打包成apk時,把raw資料夾中的檔案儲存下來。方便呼叫。缺點就是不能多層次路徑。
(01)/res/xml一般放一些xml格式的資料檔案。(可以存一些,固定的設定xml結構資料。)怎麼獲取xml資料我在這裡就不多說了。
本步驟需要一定程式碼基礎
程式程式碼以程式碼片段的形式展示