Android 布局 实验1
Android 布局 实验1
一、建立Android项目
建立项目前几篇文章已经说过了这里不再累述。
二、编写资源文件(字符文件)
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="hello">Hello</string>
<string name="app_name">Layout</string>
</resources>
三、编写资源文件(布局文件)
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:stretchColumns="1"
>
<TableRow>
<TextView
android:gravity="right"
android:text="@string/hello"
android:padding="3dip"
/>
<TextView
android:gravity="right"
android:text="@string/hello"
android:padding="3dip"
android:background="#aa0000"
/>
</TableRow>
<TableRow>
<TextView
android:gravity="right"
android:text="@string/hello"
android:padding="3dip"
android:background="#aa0000"
/>
<TextView
android:gravity="right"
android:text="@string/hello"
android:padding="3dip"
/>
</TableRow>
</TableLayout>
四、编写核心程序(屏幕)
package com.home.activity;
import android.app.Activity;
import android.os.Bundle;
public class AndroidLayout extends Activity
{
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}
五、编写清单文件
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.home.activity"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".AndroidLayout"
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>
六、运行程序
如何将项目安装在模拟器中之前文章中说过了,这里不做累述。