您的位置:首页 > 其它

游戏王千金囊开发实录三—— 主窗体(自选试题)

2012-07-01 21:24 375 查看
软件下载地址http://apk.gfan.com/Product/App231476.html

因涉及知识点过多原因,我先截图软件,展示出每个页面(作为大纲目录),后续我会编辑此类文章,补上实现该activity的关键代码.

另外,我写游戏王千金囊实录,其实有个目的,就是想让每一篇博文代表该软件一个功能,让“游戏王千金囊”的用户,能在博客的留言里反馈。

一:截图





二; 介绍

登录后的主窗体 TAB 选项卡内容之一 :自选试题,主要有功能

1,ListVIew自选试题列表 ,点击事件

2,菜单事件

3,自定义QuickAction层

4,TabHost的使用

5,首次加载创建SD卡相关文件(搬移,读取)试题文件

6,手指滑动切换TabHos窗体的功能

7,自定义窗体标题栏(window title)

三:关键代码

先从简单的功能入手,文章后面再介绍高级复杂的功能

功能一、自定义window title,可以做出漂亮的界面,换掉单调的自带应用名。

步骤一: 写xml布局,就叫window_title

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout android:id="@+id/RelativeLayout01"
android:layout_width="fill_parent" android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<TextView android:id="@+id/app_name" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_marginLeft="5.0dip"
android:text="应用名" android:layout_alignParentLeft="true"
android:layout_centerVertical="true" style="@style/ZsWindowTitle" />
<TextView android:id="@+id/app_section_name"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:text="标题" android:layout_marginRight="10dip"
android:layout_toLeftOf="@+id/btnSearch"
android:layout_centerVertical="true" android:layout_alignParentRight="true"
style="@style/ZsWindowTitle" />
</RelativeLayout>

步骤二: 要先setContentView主布局后,再getWindow().setFeatureInt ,顺序相反会报错哦

requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);

getWindow().setFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON,
WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
setContentView(R.layout.zs_main);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE,
R.layout.window_title);
TextView appName = (TextView) findViewById(R.id.app_name);
appName.setText(getString(R.string.app_name));
appTitle = (TextView) findViewById(R.id.app_section_name);
appTitle.setText("自选试题");

代码比较简单,我就不注释了

功能二、TabHost的选项卡的运用,不了解这个控件如使用,请自行查API.

实现上图的流程是, TabHosts 的addTab 方法,动态添加 Intent,点击图标切换 setCurrentTabByTag

部分代码如下

this.mNewsIntent = new Intent(this, NewsActivity.class);

mHost.addTab(buildTabSpec("news_tab", "news", this.mNewsIntent));

public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
// TODO Auto-generated method stub

if (isChecked) {
switch (buttonView.getId()) {
case R.id.radio_button0:
this.mHost.setCurrentTabByTag("fav_tab");
appTitle.setText("自选试题");
break;

//后面就略了,例如点下面新闻按钮,其实就是切换 news_tab 与改变窗体的标题
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: