android學習日記——hello word

來源:互聯網
上載者:User

目錄介紹:

gen:R.java這個檔案裡面的內容是自動產生的

assets:放置任何與項目有關的檔案

res:放在res檔案夾中的檔案會在R.java中產生一個對應ID,

res/drawable用來放置圖片 

res/layout放置布局檔案,一個activity對應一個布局檔案,

res/values應用程式中所應用到一些值,<string name="app_name">hello word</string>它以一種key value方式儲存,並且第一個都會在R.java中產生一個ID

AndroidManifest.xml整個應用程式的相關配置,

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.activityo2"//應用程式套件組合名
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="9"
        android:targetSdkVersion="15" />

    <application
        android:icon="@drawable/ic_launcher" //應用程式的表徵圖,表示引用的是drawable下的ic_launcher這張圖片
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".MainActivity"-------------------這個activity的類名
            android:label="@string/title_activity_main" >
            <intent-filter>--------------------先啟動這個activity
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity 
            android:name=".OtherActivity"
            android:label="@string/other"></activity>
    </application>
</manifest>

------------------------------------------------------------------------------------------------------------

布局檔案:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <TextView
        android:id="@+id/myTextView" -------為建立的控制項起個ID,它也會在R.java中產生對應的ID,然後我們在activity中可以用findViewById(R.id.myTextView)來得到這個控制項。
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:text="@string/hello_world"
        tools:context=".MainActivity" />

    <Button  android:id="@+id/myButton" 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        />
</RelativeLayout>

布局的方式開始最好採用LinearLayout布局

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" 
        android:orientation="vertical">
    <Button android:id="@+id/but"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/butvalue"/>
</LinearLayout>

-----------------------------------------activity--------------------------------------------

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity04);
        Button button=(Button) findViewById(R.id.but);------------通過id得到Button對象
        button.setText("按鈕");
    }

相關文章

聯繫我們

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