android学习日记——hello word

本文深入解析Android应用开发中的关键组件:如何使用R.java文件管理资源ID,如何组织布局文件以实现界面设计,以及AndroidManifest.xml文件在配置应用程序功能中的角色。通过实例展示如何创建和引用布局文件,设置应用图标与名称,以及定义启动Activity的流程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

目录介绍:

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



评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值