课程大作业 Android GUI设计
要求完成该实验的实验报告,在实验报告中需要将实验代码例出,最后要有实例心得体会。
【目的】
Android编程基础,UI设计,Button事件处理。
【要求】
1. 了解Android编程原理
2. 掌握界面控件设计
3. 掌握控件的事件处理编程
【原理】
1. View android.view.View.findViewById(int id);通过该函数,在执行期动态取得控件;
2. 通过xml布局添加Button,后台代码添加对Button的Click事件的监听;
3. 通过xml布局添加ImageButton,xml设计ImageButton背景,后台代码添加对ImageButton的Click事件的监听;
4. 通过后台代码运行期动态添加按钮及相应Click事件。
【实验内容】
1. 实验效果预览:
图1 按下按钮前 图2 按下按钮后
按钮定义
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"/>
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="Button1"/>
按下效果
Private Button mBtn;
Private TextView mText;
mBtn=(Button)findViewById(R.id.button1);
mBtn.setOnClickListener(new OnClickListener()