Android项目工作区结构

新建android项目目录包含许多文件和文件夹:
1。src存放java源程序
2.。gen 为ADT插件自动生成的代码文件保存路径,其中R.java文件将保存所有的资源ID
3。Android4.4.2 安卓SDK版本
4.assets 可以存放一些较大资源比如图片音乐字体
5。res可以存放项目中所有资源文件
6。res\drawable-hdpi res\drawable-ldpi res\drawable-mdpi保存不同分辨率的图片资源,可以使用Resources.getDrawable(id)方法获得资源类型
7。res\layout 存放所有的布局文件,主要用于排列不同的显示组件。
8。res\values 存放一些资源文件的信息,用于读取文本资源,本文件夹中有一些约定的文件名称 arrays.xml 数组数据,colors.xml颜色数据,string.xml字符串 styles.xml样式文件,dimens.xml定义尺度
9.res\raw 自定义的一些原生文件所在目录,如音乐视频文件格式。
10.res\xml 用户自定义的XML文件,所有的文件在程序中运行时编译到应用程序中。
11.res\anim 用于定义动画对象。

在安卓中新建一个项目不做任何设置 可以看到一些文件
*.java 为Activity主程序
icon.png 项目中的图片文件
main.xml 配置所有的控件
string.xml 配置字符串资源
R.java 此文件为自动生成并且自动维护,当用户添加main.xml string.xml 都会在此文件添加一个唯一ID供程序使用。
AndroidManifest.xml 为Android的主要配置文件,用于配置各个组件或一些访问权限等
default.properties Android项目属性定义文件

打开string.xml`

<?xml version="1.0" encoding="utf-8"?>
<resources>

    <string name="app_name">LearnAndroid</string>
    <string name="hello_world">Hello world!</string>
    <string name="action_settings">Settings</string>

</resources>

R.java中自动生成对应字段的ID
fragment.xml

<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"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.example.learnandroid.MainActivity$PlaceholderFragment" >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/hello_world" />

</RelativeLayout>

android:layout_width=”wrap_content” 宽度与现实文字的宽度一样
android:layout_width=”fill_content”标示组件的宽度将占据整个屏幕宽度
android:text=”@string/hello_world” 表示组件显示的内容由string.xml中的hello_world这个key决定
Acitivity主程序

public class MainActivity extends ActionBarActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        if (savedInstanceState == null) {
            getSupportFragmentManager().beginTransaction()
                    .add(R.id.container, new PlaceholderFragment()).commit();
        }
    }

setContentView(R.layout.activity_main);调用布局文件。onCreate()方法就是启动此Activity时要默认调用的方法。

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.learnandroid"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="19" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.example.learnandroid.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

@drawable/ic_launcher表示引入资源图标
android:label=”@string/app_name” 标签从string.xml中读取。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值