哈哈,在苹果手机上玩过类似游戏,在eoe上发现一个兄弟也模仿做了一个,今天趁周末自己也做了一个,借用了那位兄弟的一些美女图片,应该不涉及版权吧。程序有点yellow,希望iteye管理员高台贵手
,本意是给大家带来点乐趣。
为保护你的隐私,设置了密码保护。
下面贴部分关键代码:
@Override
public void onClick(View v) {
int id = v.getId();
switch (id) {
case R.id.yesBtn: {
SharedPreferences preferences = getSharedPreferences("password",Activity.MODE_PRIVATE);
String pwd = preferences.getString("pwd", "");
if(pwd!=null&&!"".equals(pwd)){
if(password.getText().toString()!=""&&password.getText()!=null&&password.getText().toString().equals(pwd)){
//Toast.makeText(PasswordActivity.this, "密码一致,请重新输入密码", Toast.LENGTH_SHORT).show();
Intent intent = new Intent();
intent.setClass(PasswordActivity.this, SettingsActivity.class);
startActivity(intent);
PasswordActivity.this.finish();
}else{
Toast.makeText(PasswordActivity.this, "密码不一致,请重新输入密码", Toast.LENGTH_SHORT).show();
}
}else{
SharedPreferences ferences = getSharedPreferences("password",Activity.MODE_PRIVATE);
SharedPreferences.Editor editor = ferences.edit();
editor.putString("pwd", password.getText().toString());
editor.commit();
//Toast.makeText(PasswordActivity.this, "已经设置密码", Toast.LENGTH_SHORT).show();
Intent intent = new Intent();
intent.setClass(PasswordActivity.this, SettingsActivity.class);
startActivity(intent);
PasswordActivity.this.finish();
}
}
break;
case R.id.cancelBtn: {
PasswordActivity.this.finish();
}
break;
}
}
下面是下面这张图片所显示的界面的实现,底部是一个gallery,显示大图用的是ImageSwither这个组件,一点要注意的地方是要实现ViewFactory接口并实现方法makeView();
package com.picture;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.BaseAdapter;
import android.widget.Gallery;
import android.widget.Gallery.LayoutParams;
import android.widget.ImageSwitcher;
import android.widget.ImageView;
import android.widget.ImageView.ScaleType;
import android.widget.Toast;
import android.widget.ViewSwitcher.ViewFactory;
public class MainActivity extends Activity implements ViewFactory {
private ImageSwitcher is;
private Gallery gallery;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
setupViews();
setupListener();
}
private void setupViews(){
is = (ImageSwitcher)findViewById(R.id.image_switcher);
is.setFactory(this);
gallery = (Gallery)findViewById(R.id.gallery);
gallery.setAdapter(new ImageAdapter(MainActivity.this));
}
private void setupListener(){
gallery.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view,
int position, long id) {
int drawableId = 0;
try {
drawableId = R.drawable.class.getDeclaredField(
"pre" + position).getInt(this);
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (SecurityException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (NoSuchFieldException e) {
e.printStackTrace();
}
is.setImageResource(drawableId);
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
is.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v){
Intent intent = new Intent();
intent.putExtra("imagePosition", gallery.getSelectedItemPosition());
intent.setClass(MainActivity.this, RemoveClothActivity.class);
startActivity(intent);
}
});
}
private class ImageAdapter extends BaseAdapter {
private Context mContext;
public ImageAdapter(Context c){
mContext = c;
}
@Override
public int getCount() {
return 11;//11张图片
}
@Override
public Object getItem(int position) {
return position;
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ImageView imageView = new ImageView(mContext);
int drawableId = 0;
try {
drawableId = R.drawable.class.getDeclaredField(
"pre" + position).getInt(this);
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (SecurityException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (NoSuchFieldException e) {
e.printStackTrace();
}
imageView.setLayoutParams(new Gallery.LayoutParams(120,120));
imageView.setScaleType(ScaleType.FIT_XY);
imageView.setImageResource(drawableId);
return imageView;
}
}
@Override
public View makeView() {
ImageView i = new ImageView(this);
i.setBackgroundColor(0xFF000000);
i.setScaleType(ImageView.ScaleType.FIT_CENTER);
i.setLayoutParams(new ImageSwitcher.LayoutParams(
LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
return i;
};
}

- 大小: 502 KB
分享到:
相关推荐
《Android小应用帮美女更衣系列二:源码解析与应用探索》 在移动应用开发领域,Android平台因其开源和广泛的设备支持,成为了开发者的重要舞台。本篇文章将深入探讨一个特殊的Android应用——“美女更衣”系列的第...
【标题】"(android源码)帮美女更衣"揭示了这是一个基于Android平台的游戏应用,其核心功能是允许用户操作游戏中的角色更换衣物。在Android开发中,源码是理解应用工作原理、学习编程技巧以及进行二次开发的重要...
在Android平台上,开发一款名为“帮美女更衣”的小游戏,涉及到许多关键的编程和技术知识点。首先,我们需要了解Android应用的基本架构,它通常基于组件模型,包括Activity、Service、BroadcastReceiver和...
【标题】"高仿帮美女更衣系列源码(1)"主要涉及到的是在Android平台上开发的一款模拟游戏的源代码,旨在提供一个类似"帮美女更衣"的应用体验。这样的应用通常包含各种服装、配饰的选择,用户可以自由搭配,为虚拟...
Android removeClothForBeautyGirl_美女更衣安卓游戏Java源码,点击ImageSwitcher显示的图片即可切换到为美女换衣全屏界面,手指在界面上滑动,滑动处的衣服就被褪掉了。其实是两张图片,一张底图,一张上面的图,...
【Android游戏removeClothForBeautyGirl_美女更衣】是一款基于Android平台的源码项目,主要涉及Java编程语言和Eclipse开发环境。该游戏的核心功能是允许用户为虚拟的美女角色更换衣物,提供了互动式的娱乐体验。从...
总的来说,"帮美女更衣"这款游戏的源码为我们提供了一个学习Android游戏开发的实践案例,涵盖了从基本的UI设计到复杂的动画实现、网络通信和性能优化等多个方面。通过深入研究,我们不仅可以提升编程技巧,还能更好...