main.xml解析

<?xml version="1.0" encoding="utf-8"?>
version表示当前版号 encoding表示当前编码方式

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
xmlns:android 表示XML的命名空间
android:orientation 表示方向是垂直的还是水平的
android:layout_width 整个屏幕的宽度
android:layout_height 整个屏幕的高度


<TextView android:id="@+id/tv"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text=""
/>
android:id 控件的ID
android:layout_width 控件的宽度
android:layout_height 控件的高度
android:text 控件显示的默认文字
wrap_content: 控件显示的单位

AndroidManifese.xml解析
<?xml version="1.0" encoding="utf-8"?>
version表示当前版号
encoding表示当前的编码方式

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.misoo.ex02test"
android:versionCode="1"
android:versionName="1.0">

xmlns表示xml文件所在的命名空间
package表示当前android应用所在的包
android:versionCode 版本号
android:versionName 版本名称

<application android:icon="@drawable/icon" android:label="@string/app_name">
android:icon 在进入应用前所看到的程序对应的图标
android:label 在进入应用前所看到的程序对应的名称

<activity android:name=".ex02test" android:label="@string/app_name">
android:name 表示activity的名称
android:label 表示当前屏幕的标题

<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
?????


<uses-sdk android:minSdkVersion="3" />
在androidmanifest.xml中指定最小的运行版本

strings.xml解析
<?xml version="1.0" encoding="utf-8"?>
version 版本号
encoding 解码方式

<string name="hello">Hello World</string>
name表示字符串的名称的ID, 这样使用 @strings/hello
Hello World 表示真正显示的字符串

对按纽事件处理的分析

//重写onCreate函数
public void onCreate(Bundle icicle)
{
//调用父亲的创建窗口和显示布局的函数
super.onCreate(icicle);
setContentView(R.layout.main);

//获取布局中的两个按纽
Button btn = (Button)findViewById(R.id.button);
Button btn2 = (Button)findViewById(R.id.button2);

//设定按纽事件的处理程序,又称为事件监听者。当使用者按下id值为btn或btn2
//的按纽时,框架必须把事件准确地传送到适当的类(目前是当前类this),并呼叫
//指定的函数(目前是onClick函数)
btn.setOnClickListener(this);
btn2.setOnClickListener(this);

}

//重写点击响应函数
public void onClick(View arg0)
{
//获取点击的控件的ID
switch (arg0.getId())
{
case R.id.button:
setTitle("this is OK button");
break;
case R.id.button2:
this.finish();
break;
}
}


也可以这样
public void onCreate(Bundle icicle)
{
super.onCreate(icicle);
setContentView(R.layout.main);
ImageButton btn = (ImageButton)findViewById(R.id.button);
ImageButton btn2 = (ImageButton)findViewById(R.id.button2);

MyOnClickListener sOnClickListener = new MyOnClickListener();
btn.setOnClickListener(sOnClickListener);
btn2.setOnClickListener(sOnClickListener);
}


public class MyOnClickListener extends Activity implements OnClickListener{

public void onClick(View arg0)
{
switch (arg0.getId())
{
case R.id.button:
{
int i = 1;
int j = 2;
int k = 0;
k = i + j;
setTitle("this is OK button");
break;
}

case R.id.button2:
{
this.finish();
break;
}

}
}

}

也可以这样
public void onCreate(Bundle icicle)
{
super.onCreate(icicle);
setContentView(R.layout.main);
ImageButton btn = (ImageButton)findViewById(R.id.button);
ImageButton btn2 = (ImageButton)findViewById(R.id.button2);

btn.setOnClickListener(listener);
btn2.setOnClickListener(listener);
}

OnClickListener listener = new OnClickListener()
{
public void onClick(View v) {
int i = 1;
int j = 2;
int k = 0;
k = i + j;
setTitle("this is OK button");
}
};

OnClickListener listener2 = new OnClickListener()
{
public void onClick(View v)
{
finish();
}
};

按纽背景
方法一
Button btn = (Button)findViewById(R.id.button);
btn.setBackgroundResource(R.drawable.icon);


方法二
<ImageButton android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ok"


本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/maojudong/archive/2009/09/18/4568033.aspx

更多相关文章

  1. C语言函数以及函数的使用
  2. android 获取控件真实高度
  3. android LinearLayout布局子空间没有填充父控件的问题
  4. Button、选择框、日期、时间控件
  5. 关于Linearlayout中控件设置为其底部的问题,android:layout_grav
  6. 控件的间距为0
  7. 系出名门Android(8) - 控件(View)之TextSwitcher, Gallery, Imag
  8. Android ProgressBar控件理解
  9. Android Studio开发基础之AutoCompleteTextView控件的使用

随机推荐

  1. Android 实现仿Window7图片预览窗格效果
  2. Android WebView在系统进程中无法使用
  3. Android 多行跑马灯 解决焦点抢占
  4. Android中短信的收发机制 发送短信 接收
  5. 【Android基础】页面跳转与传值(Activity
  6. 内存管理Memory Management in Android
  7. Android各个版本API的区别
  8. Android全屏(包含3种隐藏顶部状态栏及标题
  9. Android SDK Manager无法下载包的问题
  10. Android中SoundPool放声音