Wordroid项目全解析
——By 吴昊
我们只能说,不借助于模板,还是很困难的(毕竟,我们对安卓组件的熟悉还没有达到那种随手擒来的这种境地)。但是,我最终还是想出了一种办法,乃是三合一。将我们做的一部分+iword的单词库+BUPT的一部分Source整合,配上我们自己的图片,这是我们的最终策略,作为一个合格的产品,没有问题了,但是,考虑在算法上面的改进,将最后留一个月来完成吧!
其中项目的截图我采用的是中国移动开发者社区提供的终端池—远程测试功能,因为自己的模拟器各种故障,如图所示:(测试的机型为SUMSUNG i9000 Galaxy S 8G)
先看BUPT的Wordroid,整个项目解剖如下:
Wordroid.activitys包:
菜单栏目:
(1) 关于(about.java)
package wordroid.activitys;
import wordroid.model.R;
import android.app.Activity;
import android.os.Bundle;
public class about extends Activity {
@Override
//在重写中打开login布局
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
this.setContentView(R.layout.login);
}
}
(login.xml)
//这里将其宽与高拉到最大,然后将背景设置为一张既有的图片
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/login">
</LinearLayout>
我们的修改:关于部分,主要是记录版权信息,我们这里引入一张图片为宜(我们的towords还没有这种功能,可以补上)
(2) 帮助(Help.java)
首先在values文件夹的strings.xml中定义如下的一些字符串(字符串的名字和键值,同时会生成相应的R文件)
在Help类中,将其从上往下排列出来:
package wordroid.activitys;
import wordroid.model.R;
import android.app.Activity;
import android.os.Bundle;
import android.widget.ScrollView;
import android.widget.TextView;
public class Help extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
this.setContentView(R.layout.showabout);
TextView tv = (TextView) this.findViewById(R.id.about_title);
tv.setText("安卓背单词-Wordroid 帮助");
TextView words = (TextView) this.findViewById(R.id.about_words);
words.setText(R.string.words);
TextView abs = (TextView) this.findViewById(R.id.about_abstract);
abs.setText(R.string.abs);
TextView learn = (TextView) this.findViewById(R.id.about_learn);
learn.setText(R.string.learn);
TextView review = (TextView) this.findViewById(R.id.about_review);
review.setText(R.string.review);
TextView test = (TextView) this.findViewById(R.id.about_test);
test.setText(R.string.test);
TextView attetion = (TextView) this.findViewById(R.id.about_attention);
attetion.setText(R.string.attetion);
}
}
对于Help类的布局showabout.xml,没有什么值得说的吧,对第一个字符串,也就是“安卓背单词-Wordroid帮助”不设置移动,对于后面的布局开启一个ScrollView,这样可以进行拖动处理,如下,竖直排列七个字符串
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/main_back"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:id="@+id/about_title"
android:textColor="#000000"
android:textSize="20px"
/>
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/scrollView"
>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#000000"
android:id="@+id/about_abstract"
android:textSize="16px"
/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#000000"
android:id="@+id/about_words"
android:textSize="16px"
/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#000000"
android:id="@+id/about_learn"
android:textSize="16px"
/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#000000"
android:id="@+id/about_review"
android:textSize="16px"
/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#000000"
android:id="@+id/about_test"
android:textSize="16px"
/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#000000"
android:id="@+id/about_attention"
android:textSize="16px"
/>
</LinearLayout>
</ScrollView>
</LinearLayout>
我们这里与之不同,我们设置三张图片,利用onFling来实现滑动,利用返回键返回来主菜单。
(3) 设置(类似于我们的option功能)
设置按钮的布局——Preferences.xml
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android">
<PreferenceCategory android:title="复习提醒功能">
//方形框设置是否定时提醒
<CheckBoxPreference
android:key="notify"
android:title="定时提醒"
//这个定时提醒title是一个方形的选项,有开启和关闭两种模式
android:summaryOn=" 开启 "
android:summaryOff=" 关闭 "
android:defaultValue="true"
/>
//这里设置一个widget,就是对时间的设置