Android 布局 实验3

Android 布局 实验3

Android 布局 实验2

一、建立Android项目

建立项目前几篇文章已经说过了这里不再累述。

二、编写资源文件(字符文件)


 

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="hello">Hello World, LayOut!</string>
    <string name="app_name">AndroidLayout</string>
    <string name="test">这个是从主Activity直接跳过来的</string>
</resources>



 

三、编写资源文件(布局文件)

main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
    <LinearLayout 
	    android:orientation="horizontal"
	    android:layout_width="fill_parent"
	    android:layout_height="fill_parent"
	    android:layout_weight="1"
    	>
    
			<TextView  
			    android:layout_width="fill_parent" 
			    android:layout_height="wrap_content" 
			    android:text="@string/hello"
			    android:layout_weight="1"
			    android:background="#aa0000"
			    />
			<TextView  
			    android:layout_width="fill_parent" 
			    android:layout_height="wrap_content" 
			    android:text="@string/hello"
			    android:layout_weight="1"
			    android:background="#00aa00"
			    />
			<TextView  
			    android:layout_width="fill_parent" 
			    android:layout_height="wrap_content" 
			    android:text="@string/hello"
			    android:layout_weight="1"
			    android:background="#0000aa"
			    />
    </LinearLayout>
    <LinearLayout 
	    android:orientation="horizontal"
	    android:layout_width="fill_parent"
	    android:layout_height="fill_parent"
	    android:layout_weight="1"
    	>
    	<TableLayout
    		android:layout_width="fill_parent"
    		android:layout_height="fill_parent"
    		>
    		<TableRow
    			android:layout_weight="1"
    			>
					<TextView  
					    android:layout_width="fill_parent" 
					    android:layout_height="wrap_content" 
					    android:text="@string/hello"
					    android:layout_weight="1"
					    />
					<TextView  
					    android:layout_width="fill_parent" 
					    android:layout_height="wrap_content" 
					    android:text="@string/hello"
					    android:layout_weight="1"
					    />
					<TextView  
					    android:layout_width="fill_parent" 
					    android:layout_height="wrap_content" 
					    android:text="@string/hello"
					    android:layout_weight="1"
					    />
				    </TableRow>
    		<TableRow
    			android:layout_weight="1"
    			>
					<TextView  
					    android:layout_width="fill_parent" 
					    android:layout_height="wrap_content" 
					    android:text="@string/hello"
					    android:layout_weight="1"
					    />
					<TextView  
					    android:layout_width="fill_parent" 
					    android:layout_height="wrap_content" 
					    android:text="@string/hello"
					    android:layout_weight="1"
					    />
					<TextView  
					    android:layout_width="fill_parent" 
					    android:layout_height="wrap_content" 
					    android:text="@string/hello"
					    android:layout_weight="1"
					    />
				    </TableRow>
			    </TableLayout>
    </LinearLayout>
</LinearLayout>

test.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
					<TextView  
					    android:layout_width="fill_parent" 
					    android:layout_height="wrap_content" 
					    android:text="@string/test"
					    android:layout_weight="1"
					    />
</LinearLayout>


 

四、编写核心程序(屏幕)

LayOut.java

package com.home.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;

public class LayOut extends Activity
{
	@Override
	public void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		
		/*这个是从一个Activity直接跳到另一个Activity*/
		myListener listener = new myListener();
		View v = new View(getBaseContext());
		listener.onClick(v);
	}
	
	class myListener implements OnClickListener
	{
		@Override
		public void onClick(View v)
		{
			Intent intent = new Intent();
			
			intent.setClass(LayOut.this, TestActivity.class);
			LayOut.this.startActivity(intent);
			
		}
	}
}


TestActivity.java

package com.home.activity;

import android.app.Activity;
import android.os.Bundle;

public class TestActivity extends Activity
{
	@Override
	protected void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
		setContentView(R.layout.test);
	}
}


 

五、编写清单文件

 

 

<?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=".LayOut"
                  android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name=".TestActivity"
                  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> 



 

六、运行程序

如何将项目安装在模拟器中之前文章中说过了,这里不做累述。

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值