公司培训了编码规范,回头过来看看我以前写过的代码,着实比较烂,缺少必要的注释,以及对于变量名的定义也不甚规范,故借着此次学习,我重新整理下一篇安卓项目的文章,规范下代码,可以用doxygen生成html文件,以便方便别人阅读源码以及以后自己回顾自己的成果,并且希望能够慢慢培养成规范的习惯。
源文章的地址是:http://blog.youkuaiyun.com/jjzhoujun2010/article/details/7976858
整个项目的主要思想和步骤是:
1.个性化安装图标的定制。
2.进入程序,播放背景音乐。
3.进行拼图游戏。
4.游戏过关后进入下一个界面,有两个按钮,点击即可实现给指定号码拨号功能。
由于源码我注释得也比较清楚了,直接上源码给大家看吧~
第一个界面的实现代码,Main.java
/**
* @file Main.java
* @brief 整个程序的功能:实现一个手机拼图程序,并且带有自动拨号功能
*
* 整个项目的主要思想和步骤是:
* 1.个性化安装图标的定制。
* 2.进入程序,播放背景音乐。
* 3.进行拼图游戏。
* 4.游戏过关后进入下一个界面,有两个按钮,点击即可实现给指定号码拨号功能。
* Blog: http://blog.youkuaiyun.com/jjzhoujun2010
*
* @author zhoujun
* @version V1.0.00
* @date 2012/09/12
*/
package com.example.zhangbeta2;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Gravity;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.Toast;
/**
* @brief 实现一个手机拼图程序,并且带有自动拨号功能
* */
public class Main extends Activity {
private Intent mIntent = new Intent("com.angel.Android.MUSIC");
Button mButtonNext = null;
Button mButtonExit = null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
startService(mIntent); //开启背景音乐
mButtonNext = (Button)findViewById(R.id.buttonNext);
mButtonNext.setOnClickListener(new NextButtonListener());
mButtonExit = (Button)findViewById(R.id.buttonExit);
mButtonExit.setOnClickListener(new ExitButtonListener());
}
/**
* @brief 本类功能:设置下一步按钮监听器,点击按钮跳转到相应拼图游戏的Activity中
*/
class NextButtonListener implements OnClickListener{
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
// 点击相应按钮,跳转到拼图界面activity
Intent intent = new Intent();
intent.setClass(Main.this, SePintu.class);
startActivity(intent);
}
}
/**
* @brief 本类功能:设置退出按钮监听器,点击按钮弹出Toast,关闭背景音乐,并且退出整个程序
*/
class ExitButtonListener implements OnClickListener{
private Toast toast;
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
toast = Toast.makeText(getApplicationContext(), "无论如何,都希望你快乐幸福", Toast.LENGTH_LONG);
toast.setGravity(Gravity.CENTER, 0, 0);
LinearLayout toastView = (LinearLayout)toast.getView();
ImageView imageCodeProject = new ImageView(getApplicationContext());
imageCodeProject.setImageResource(R.drawable.pic3);
toastView.addView(imageCodeProject, 0);
toast.show();
finish();
stopService(mIntent); //关闭背景音乐
// android.os.Process.killProcess(android.os.Process.myPid());
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
跳转到第二个界面的实现代码,SePintu.java
/**
* @file SePintu.java
* @brief 显示拼图游戏界面,此图片是被打乱了的拼图
* @author zhoujun
* @version V1.0.00
* @date 2012/09/12
* Blog: http://blog.youkuaiyun.com/jjzhoujun2010
*/
package com.example.zhangbeta2;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Matrix;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.ImageView.ScaleType;
import android.widget.Button;
import android.widget.LinearLayout;
/**
* @brief 显示拼图游戏界面,此图片是被打乱了的拼图
* */
public class SePintu extends Activity{
private int mLevelNow = 4;
private ImageView mImages[][]; //存放小图片的数组
private Bitmap mBitmap; //资源图片
private int mImageWidth = 0, mImageHeight = 0; //slot的宽高
private int mImageNum[]; //图片的顺序
private int mX = 0, mY = 0; //图片的起始位置
private int mClickNum = 0; //点击参数
private int mWindowWidth = 0, mWindowHeight = 0; //屏幕参数
@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
// pic1 = (ImageView)findViewById(R.id.pic1);
mBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.pic1);
System.out.println("width = " + mBitmap.getWidth() + "height = " + mBitmap.getHeight());
//屏幕参数
WindowManager w = this.getWindowManager();
mWindowHeight = w.getDefaultDisplay().getHeight();
mWindowWidth = w.getDefaultDisplay().getWidth();
System.out.println("wWidth = " + mWindowWidth + "wHeight = " + mWindowHeight);
setImage();
}
/**
* @brief 将一副图片分割成几个小部分打乱
*/
public void setImage() {
mImageWidth = mBitmap.getWidth() / mLevelNow; //切割图片,每一小块的宽度
mImageHeight = mBitmap.getHeight() / mLevelNow;
mImageNum = new int[mLevelNow * mLevelNow];
System.out.println("mIWidth = " + mImageWidth + "mImageHeight = " + mImageHeight);
erraLen(mLevelNow * mLevelNow); //随机组合切碎的小图片
readyImage();
setLayout(); //布局随机组合后的图片
}
/**
* @brief 在当前的Activity中显示打乱后的拼图以及相应按钮
* */
private void setLayout() {
PictureLayout lay = new PictureLayout(this, mImages); //利用带参数的构造函数来布局小图片
lay.setOrientation(LinearLayout.VERTICAL);
lay.setGravity(Gravity.CENTER_HORIZONTAL);
setContentView(lay); //显示lay布局,SePintu的Activity
Button methodButton = new Button(this);
methodButton.setText(R.string.method_btn_label);
methodButton.setOnClickListener(new MethodBtnClick()); //添加监听器
Button showSourceImageBtn = new Button(this);
showSourceImageBtn.setText(R.string.show_source_image_btn_label);
showSourceImageBtn.setOnClickListener(new SourceBtnClick());
LinearLayout linear = new LinearLayout(this);
//注意,对于LinearLayout布局来说,设置横向还是纵向是必须的!否则就看不到效果了。
linear.setOrientation(LinearLayout.HORIZONTAL);
//此处相当于布局文件中的Android:gravity属性
linear.setGravity(Gravity.CENTER_HORIZONTAL);
methodButton.setWidth(200);
showSourceImageBtn.setWidth(200);
linear.addView(methodButton); //通过addView将两按钮添加到布局中
linear.addView(showSourceImageBtn);
lay.addView(linear); //把linear当作子child添加到lay布局中
}
/**
* @brief 点击“游戏说明”按钮,跳转到相应的Activity中
* */
class MethodBtnClick implements OnClickListener{
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent = new Intent();
intent.setClass(SePintu.this, Method.class);
startActivity(intent); //跳转Activity
}
}
/**
* @brief 点击“查看原图”按钮,显示出未打乱的原图
* */
class SourceBtnClick implements OnClickListener{
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent = new Intent(SePintu.this, SourceImageAty.class);
startActivity(intent); //跳转Activity
}
}
/**
* @brief 把一个有序数组通过随机取数打乱
* @param lenght 数组大小,随机数的范围
*/
public void erraLen(int lenght) {
int errInt[] = new int[lenght];
for (int i = 0; i < lenght; i++) {
errInt[i] = i;
}
int len = lenght;// 设置随机数的范围
for (int i = 0; i < lenght; i++) {
int index = (int) Math.floor((Math.random() * len));
mImageNum[i] = errInt[index];
for (int j = index; j < errInt.length - 1; j++) {
// 把选中的数之后的数一次向前移一位,因为index选中的数已经存放在相应的mImageNum里面了,
errInt[j] = errInt[j + 1];
}
len--;// 随机数的范围减一
}
}
/**
* @brief 准备图片 把一张图片截成几张小的通过打乱的数组来取cache里的图片放到View里面就成打乱二维数组
*/
private void readyImage() {
Matrix matrix = new Matrix();
mImages = new ImageView[mLevelNow][mLevelNow];
// 设置缩放比例
// float scaleW = ((float) mBitmap.getWidth()) / mBitmap.getWidth();
// float scaleH = ((float) mBitmap.getHeight()) / mBitmap.getHeight();
float scaleW = ((float) mBitmap.getWidth()) / (mWindowWidth + 180);
float scaleH = ((float) mBitmap.getHeight()) / (mWindowHeight + 180);
System.out.println("scaleW = " + scaleW +" scaleH" + scaleH);
float scale = scaleW > scaleH ? 1 / scaleW : 1 / scaleH; //scale是缩放比例,取最小比例的进行缩放
System.out.println("scale = " + scale);
matrix.postScale(scale, scale);
Bitmap bitss[][] = new Bitmap[mLevelNow][mLevelNow];
ImageView[][] cache = new ImageView[mLevelNow][mLevelNow];
int cont = 1;
for (int i = 0; i < mLevelNow; i++) {
for (int j = 0; j < mLevelNow; j++) {
int mX = i * mImageWidth;
int mY = j * mImageHeight;
// 第一个是要在那个图片上截取 mX,y是要在这个图的那个位置截取
// mImageWidth,mImageHeight是截取的长和宽, matrix是缩放比例
Bitmap mapi = Bitmap.createBitmap(mBitmap, mX, mY, mImageWidth,
mImageHeight, matrix, true);
bitss[i][j] = mapi;
ImageView img = new ImageView(this);
BitmapDrawable draw = new BitmapDrawable(bitss[i][j]);
img.setImageDrawable(draw);
img.setId(cont);
img.setScaleType(ScaleType.FIT_XY);
img.setOnClickListener(OnClickImageView1);
cache[i][j] = img; //cache存放着整张图切割后的小图片
cont++;
}
}
for (int i = 0; i < mImageNum.length; i++) {
int mX = mImageNum[i] / mLevelNow; //确定第几行
int mY = mImageNum[i] % mLevelNow; //确定第几列
int x1 = i / mLevelNow;
int y1 = i % mLevelNow;
mImages[x1][y1] = cache[mX][mY]; //将cache里面的小图片随机放入mImages数组里面
}
}
/**
* @brief 监听点击操作,以便判断是否需要互相交换小图片
* */
private android.view.View.OnClickListener OnClickImageView1 = new ImageView.OnClickListener() {
@Override
public void onClick(View v) {
if (mClickNum == 0) {// 即需要交换的第一个图片
for (int i = 0; i < mImages.length; i++) {
boolean f = false;
for (int j = 0; j < mImages[i].length; j++) {
ImageView imgg = mImages[i][j];
if (imgg == v) { //所点击的刚好是指定的小图片区域
mX = i;
mY = j;
mClickNum++; //点击了一次
f = true;
break;
}
}
if (f) {
break;
}
}
} else {// 即需要交换的第二个图片
for (int i = 0; i < mImages.length; i++) {
for (int j = 0; j < mImages[i].length; j++) {
ImageView imgg = mImages[i][j];
if (imgg == v) {
if (mClickNum == 1) {
changePosition(i, j, mX, mY);
mX = 0;
mY = 0;
mClickNum = 0;
}
}
}
}
}
}
};
/**
* @brief 判断是否需要互相交换小图片
* @param x1 第一张图片左上角x坐标的值
* @param y1 第一张图片左上角y坐标的值
* @param x2 第二张图片左上角x坐标的值
* @param y2 第二张图片左上角y坐标的值
* */
private void changePosition(int x1, int y1, int x2, int y2) {
// 判断宽和高差的绝对值是否是1,如果是1的话交换两张图片,不是1的话提示用户
if (Math.abs(x1 - x2) + Math.abs(y1 - y2) != 1) {
System.out.println("not link....");
Builder bul = new AlertDialog.Builder(this); //弹出相应对话框
bul.setTitle(R.string.dialog);
bul.setMessage(R.string.cannot_change);
bul.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
}).show();
} else { //相邻,两张图片进行交换
System.out.println("link....");
String str = "";
ImageView bitF = null;
bitF = mImages[x1][y1];
mImages[x1][y1] = mImages[x2][y2];
mImages[x2][y2] = bitF;
for (int i = 0; i < mImages.length; i++) {
for (int j = 0; j < mImages[i].length; j++) {
ImageView img = mImages[i][j];
//得到ImageView的父控件
LinearLayout pa = (LinearLayout) img.getParent();
// 再移除ImageView使其父控件没有,移除父控件,重新用setLayout()进行布局
pa.removeView(img);
}
}
setLayout(); //将进行变换操作的图片显示出来
for (int i = 0; i < mImages.length; i++) {
for (int j = 0; j < mImages[i].length; j++) {
str += mImages[i][j].getId(); //取对应小图片的ID,相当于R.id.mImages[i][j]
}
}
//根据具体切割次数mLevelNow,判断最后一次变换是否已经拼好
switch (mLevelNow) {
case 2:
if (str.equals("1324")) {
// “1324”的意思是,将图片2*2地切割,有四块,标号先竖着,然后再横着来1234,根据getId取值互相比较
this.success();
}
break;
case 3:
if (str.equals("147258369")) {
this.success();
}
break;
case 4:
if (str.equals("15913261014371115481216")) {
this.success();
}
break;
case 5:
if (str.equals("16111621271217223813182349141924510152025")) {
this.success();
}
break;
}
}
}
/**
* @brief 完成拼图后,提示成功完成对话框,点击按钮进入下一个Activity界面
*/
public void success() {
Builder bul = new AlertDialog.Builder(this);
bul.setTitle(R.string.dialog);
bul.setMessage(R.string.congratulation);
bul.setPositiveButton(R.string.next_Label, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Intent intent = new Intent(SePintu.this, TheEnd.class);
SePintu.this.startActivity(intent); //点击确定后跳转到下一个Activity
}
});
bul.show();
System.out.println("success");
}
}
通过构造函数,进行画图布局,PictureLayout.java
/**
* @file PictureLayout.java
* @brief 重新布置打乱后的拼图
* @author zhoujun
* @version V1.0.00
* @date 2012/09/12
* Blog: http://blog.youkuaiyun.com/jjzhoujun2010
*/
package com.example.zhangbeta2;
import android.content.Context;
import android.widget.ImageView;
import android.widget.LinearLayout;
/**
* brief 重新布置打乱后的拼图
* */
public class PictureLayout extends LinearLayout{
public PictureLayout(Context context, ImageView[][] images) {
super(context);
setLayout(context, images);
setBackgroundColor(0xffff7777); //为了和照片边缘区分开,我添加了背景颜色
}
/**
* @brief 重新布置打乱后的拼图
* @param view 当前被拆分打乱的照片
* */
private void setLayout(Context context, ImageView[][] view) {
LinearLayout linralayout = new LinearLayout(context);
linralayout.setOrientation(LinearLayout.VERTICAL);
linralayout.setPadding(0, 0, 0, 0);
for (int i = 0; i < view.length; i++) {
LinearLayout liner = new LinearLayout(context);
liner.setOrientation(LinearLayout.HORIZONTAL);
int leng = view[i].length;
for (int j = 0; j < leng; j++) {
ImageView img = (ImageView) view[i][j];
liner.addView(img);
}
linralayout.addView(liner);
liner = null;
}
this.addView(linralayout);
}
}
游戏原图显示,SourceImageAct.java
/**
* @file SourceImageAty.java
* @brief 显示未打乱的原图
* @author zhoujun
* @version V1.0.00
* @date 2012/09/12
* Blog: http://blog.youkuaiyun.com/jjzhoujun2010
*/
package com.example.zhangbeta2;
import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
/**
* @brief 显示未打乱的原图
* */
public class SourceImageAty extends Activity{
private ImageView mPic1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.source);
mPic1 = (ImageView)findViewById(R.id.pic1);
Bitmap bitmap1 = BitmapFactory.decodeResource(getResources(), R.drawable.pic1);
mPic1.setImageBitmap(bitmap1);
mPic1.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
finish(); //点击屏幕图片即退出当前Activity
}
});
}
}
游戏方法Activity, Method.java
/**
* @file Method.java
* @brief 实现拼图游戏里面“游戏说明”的Activity
* @author zhoujun
* @version V1.0.00
* @date 2012/09/12
* Blog: http://blog.youkuaiyun.com/jjzhoujun2010
*/
package com.example.zhangbeta2;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
/**
* @brief 实现点击拼图游戏里面“游戏说明”按钮后跳转后的Activity
* */
public class Method extends Activity{
Button mBackBtn = null;
@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.method);
mBackBtn = (Button)findViewById(R.id.backBtn);
mBackBtn.setOnClickListener(new backOnClickListener());
}
/**
* @brief 本类功能:设置返回按钮监听器,点击按钮销毁当前Activity,返回拼图游戏Activity
*/
class backOnClickListener implements OnClickListener{
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
finish();
}
}
}
最后界面,TheEnd.java
/**
* @file TheEnd.java
* @brief 最后的显示界面,包含两个来实现自动播放功能的按钮
* @author zhoujun
* @version V1.0.00
* @date 2012/09/12
* Blog: http://blog.youkuaiyun.com/jjzhoujun2010
*/
package com.example.zhangbeta2;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
/**
* @brief 最后的显示界面,包含两个来实现自动播放功能的按钮
*/
public class TheEnd extends Activity{
private Intent mIntentMusic = new Intent("com.angel.Android.MUSIC");
@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.end);
setCompenent();
}
/**
* @brief 设置按钮,点击相应按钮,自动给指定号码进行拨号
* */
private void setCompenent(){
Button callExitBtn = (Button)findViewById(R.id.call_exit);
callExitBtn.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent = new Intent(
Intent.ACTION_CALL, Uri.parse("tel:10086")); //自动拨号,由于隐私,改成10086.。。
stopService(mIntentMusic);
startActivity(intent);
}
});
Button exitCallBtn = (Button)findViewById(R.id.exit_call);
exitCallBtn.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent = new Intent(
Intent.ACTION_CALL, Uri.parse("tel:10086"));
stopService(mIntentMusic);
startActivity(intent);
}
});
}
}
背景音乐实现,MusicServer.java
/**
* @file MusicServer.java
* @brief 开启一个Server,用来自动播放背景音乐
* @author zhoujun
* @version V1.0.00
* @date 2012/09/12
* Blog: http://blog.youkuaiyun.com/jjzhoujun2010
*/
package com.example.zhangbeta2;
import android.app.Service;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.IBinder;
/**
* @brief 继承一个服务,用来播放背景音乐
* */
public class MusicServer extends Service {
private MediaPlayer mMediaPlayer;
/**
* @brief 绑定对应的intent
* @return null
*/
@Override
public IBinder onBind(Intent intent) {
// TODO Auto-generated method stub
return null;
}
/**
* @brief 根据intent,打开背景音乐
*/
@Override
public void onStart(Intent intent,int startId){
super.onStart(intent, startId);
if(mMediaPlayer==null){
// R.raw.happy是资源文件,MP3格式的,存放在res资源下raw文件夹里,没有的话新建个
mMediaPlayer = MediaPlayer.create(this, R.raw.happy);
mMediaPlayer.setLooping(true);
mMediaPlayer.start();
}
}
/**
* @brief 关闭背景音乐
*/
@Override
public void onDestroy() {
// TODO Auto-generated method stub
super.onDestroy();
mMediaPlayer.stop();
}
}
JAVA文件就这些,剩下就是xml文件了。
main.xml文件如下
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="@drawable/background">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#abcdef"
android:text="@string/hello_world"
tools:context=".Main" />
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<Button
android:id="@+id/buttonNext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/next"
/>
<Button
android:id="@+id/buttonExit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/exit"
/>
</LinearLayout>
</LinearLayout>
method.xml文件如下
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/method_detail"/>
<Button
android:id="@+id/backBtn"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/back_label"/>
</LinearLayout>
source.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:orientation="vertical"
android:background="#ffff7777">
<ImageView
android:id="@+id/pic1"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
</ImageView>
</LinearLayout>
end.xml文件如下
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:background="@drawable/cake_bak">
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:id="@+id/call_exit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/call_exit"/>
<Button
android:id="@+id/exit_call"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/exit_call"/>
</LinearLayout>
</LinearLayout>
AndroidManifest.xml文件如下
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.zhangbeta2"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".Main"
android:label="@string/title_activity_main"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".SePintu"
android:label="@string/label_pintu1"/>
<activity
android:name=".Method"
android:label="@string/method_label"/>
<activity
android:name=".TheEnd"
android:label="@string/label_theEnd"/>
<activity
android:name=".SourceImageAty"
android:label="@string/source_back_label"/>
<service android:name=".MusicServer">
<intent-filter>
<action android:name="com.angel.Android.MUSIC"/>
<category android:name="android.intent.category.default" />
</intent-filter>
</service>
</application>
<uses-permission android:name="android.permission.CALL_PHONE"></uses-permission>
</manifest>
在我的测试中,我发现存在以下几个问题,(1)当我用Service来播放背景音乐时候,如果是通过键盘上返回键退出的话,就不会stopService,背景音乐就一直播放,由于赶着送出去的时间关系,我没有修复它,上网查了下可以通过重写onKeyDown按键,来实现关闭音乐。(2)分辨率的问题,我主要是针对4.0屏幕设计的,有时候用的是fill_parent,有时候不同屏幕会造成图片的变形。若各位有更好的方法,欢迎交流。
应用程序APK下载地址:http://download.youkuaiyun.com/detail/jjzhoujun2010/4568777
源码下载地址:http://download.youkuaiyun.com/detail/jjzhoujun2010/4635304
参考文章: - - 不好意思,综合看得太多了,记不得那个了,其中拼图的打乱算法我是参考别人的,若有人看到此文章,请告诉我链接,多谢。
原创文章,欢迎转载,转载请注明:https://ifish.site/android-gift.html
优快云: blog.youkuaiyun.com/jjzhoujun2010
作者:Dream Fly