Android應用程式的解析

來源:互聯網
上載者:User

標籤:

一: 檔案架構

 

二: 圖片,語音資源的使用

    圖片的兩種使用方法:

    第一種: 使用imageView控制項           

     <ImageView        android:id="@+id/imageView1"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:src="@drawable/logo" />

        第二種: 使用imageView控制項

public class mainActivity extends Activity {    /** Called when the activity is first created. */    @Override    public void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        //建立ImageView對象        ImageView iv = new ImageView(this);        //為ImageView進行設定 ,將圖片設定給對象        iv.setImageBitmap(BitmapFactory.decodeResource(        getResources(), R.drawable.logo));        //將我們的ImageView對象放置到當前VIew        this.setContentView(iv);                //不使用載入XML的布局管理器        //setContentView(R.layout.main);    }}

  語音的使用方法:使用MediaPlayer類

public void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);                        //將我們的聲音資源檔設定給MediaPlayer對象        mMdeiaPlayer = MediaPlayer.create(this, R.raw.midi);                setContentView(R.layout.main);      //將MediaPlayer運行起來.Start();        mMdeiaPlayer.start();        //如果我們要停止聲音,我們使.stop();    }

  

三: AndroidManifest.xml 添加應用許可權

<application        android:icon="@drawable/ic_launcher"        android:label="@string/app_name" >        <activity            android:name=".mainActivity"            android:label="@string/app_name" >            <intent-filter>                <action android:name="android.intent.action.MAIN" />                <category android:name="android.intent.category.LAUNCHER" />            </intent-filter>            <uses-permission  android:name="android.permission.SEND_SMS"/>        </activity>    </application><uses-permission  android:name="android.permission.SEND_SMS"/></manifest>

  

Android應用程式的解析

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.