返学费网 > 培训机构 > 厦门新博教育

4008508622

全国统一学习专线 8:30-21:00

Android中布局和Listener的联系因为刚开始学习Android,所以毕竟对其高深的东西也很不了解,先从布局开始:
1. main.xml -- 主要的布局xml文件,个人感觉写起来很繁琐,希望Google能给个像Flex Builder一样的工具可以挂到Eclipse当中使用,例如直接拖拽之类的。 复制内容到剪贴板 代码:< ?xml version="1.0" encoding="utf-8"?>
< RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
androidrientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
< LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
id="@+id/top"
androidrientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
< TextView id="@+id/show"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Hello World, viewActivity"
/>
< TextView id="@+id/show"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Input Your name : "
/>
< EditText id="@+id/name"
android:layout_width="120px"
android:layout_height="30px"
android:layout_toRight="@id/show"
/>
< /LinearLayout>
< Button id="@+id/btnOk"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/top"
android:layout_alignParentRight="false"
android:layout_marginLeft="20px"
android:text="OK"
/>
< Button id="@+id/cancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/top"
android:layout_toRight="@id/btnOk"
android:layout_marginLeft="20px"
android:text="Cancel"
/>
< /RelativeLayout>
尤其是在上面如果要进行复杂些的排版的时候就显得格外繁琐了,但还好只是在gphone上开发,还是算勉强。
还有就是我没有找到哪能写%号,如果要是可以到话就更好了。
2.Activity的子类 viewActivity 复制内容到剪贴板 代码:package com.binbinming.vince.test;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class viewActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
//find OK button ,and add listen to it.
Button btnOk = (Button)this.findViewById(R.id.btnOk);
Button btnCancel = (Button)this.findViewById(R.id.cancel);
btnOk.setOnClickListener(okListener);
btnCancel.setOnClickListener(okListener);
}
Create anonymous class for click listener
private OnClickListener okListener = new OnClickListener()
{
public void onClick(View v)
{
if(v.getId() == R.id.btnOk){
setResult(RESULT_OK, "Great Vince!");
showAlert("Nice Vince_bin", "vince_bin@yahoo.com", "ok", true);
}else{
finish();
}
}
};
}
 

温馨提示:为不影响您的学业,来校区前请先电话咨询,方便我校安排相关的专业老师为您解答
  • 详情请进入厦门新博教育
  • 已关注:403
  • 咨询电话:
  • 热门课程
姓名不能为空
手机号格式错误