android学习日记——hello word

来源:互联网 发布:教育软件排名 编辑:程序博客网 时间:2024/06/04 18:13

目录介绍:

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("按钮");
    }



原创粉丝点击