安卓學習-資源訪問

來源:互聯網
上載者:User

標籤:

安卓學習-資源訪問

1.靜態原生的資源,都儲存在assets裡,如db,mp3等

2.其他的一般都通過R.訪問

 

目錄 存放資源 說明
/res/animator 屬性動畫的XML  顏色切換動畫;3D旋轉動畫
/res/anim 補件動畫的XML  只能支援簡單的縮放、平移、旋轉、透明度基本的動畫,且有一定的局限性
 /res/color  顏色  
 /res/drawable

 存放各種位元影像檔案和Drawable的XML檔案

如:

*.png,*.9.png,*.jpg,*.gif

BitmapDrawable

NinePatchDrawable

StateListDrawable

ShapeDrawable

AnimationDrawable

Drawable各類其他子物件

 NinePatchDrawable(*.9.png)

StateListDrawable根據不同狀態,變換背景色

ShapeDrawable 畫圖用的

AnimationDrawable 動畫

 /res/layout  存放介面布局檔案  
 /res/menu 存放菜單   
 /res/raw

 存放一些原生資源,如聲音、視頻等

 

InputStream in=getResources().openRawResource(R.raw.aaa);

現在已經不建議放這裡了,直接放assets

然後通過InputStream in=getResources().getAssets().open("aaa.txt");

 這些資料只能讀取,不能寫入。更重要的是該目錄下的檔案大小不能超過1M。

 

 /res/values

 自定各種資源檔

如:

arrays.xml

strings.xml

colors.xml

demens.xml

styles.xml

 
 /res/xml  原生的xml檔案可以存放在這裡  
try {            XmlResourceParser xml = getResources().getXml(R.xml.bbb);            xml.next();            int eventType = xml.getEventType();            while (eventType != XmlPullParser.END_DOCUMENT) {                // 如過到達標記的節點則取出內容                if (eventType == XmlPullParser.TEXT) {                    Log.v("weijj", EncodingUtils.getString(xml.getText().getBytes(), "utf-8"));                }                xml.next();                eventType = xml.getEventType();            }        } catch (Exception e) {            e.printStackTrace();        }
View Code

 

 

Drawable資源使用

1.BitmapDrawable

        Drawable drawable=getResources().getDrawable(R.drawable.ic_launcher);        ImageView imageView1=(ImageView)findViewById(R.id.imageView1);        imageView1.setBackground(drawable);

2.StateListDrawable

 支援的狀態

屬性值 含義
android:state_active 啟用狀態
android:state_checkable 可勾選狀態
android:state_checked 已勾選
android:state_enabled 可用
android:state_first 開始狀態
android:state_focused 得到焦點狀態
android:state_last 結束狀態
android:state_middle 中間狀態
android:state_pressed 被安裝狀態
android:state_selected 被選中狀態
android:state_window_focused 視窗是否已獲得焦點

安卓學習-資源訪問

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.