精华帖 (2) :: 良好帖 (2) :: 新手帖 (0) :: 隐藏帖 (0)
|
|
---|---|
作者 | 正文 |
发表时间:2011-10-22
最后修改:2011-10-24
哈哈,在苹果手机上玩过类似游戏,在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; }; } 声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
返回顶楼 | |
发表时间:2011-10-24
哎,答题答得我好辛苦啊!
|
|
返回顶楼 | |
发表时间:2011-10-24
效果很不错啊,多谢多谢。
为什么很多人都只下载而不回复呢? |
|
返回顶楼 | |
发表时间:2011-10-24
最后修改:2011-10-24
看来这个应用的难点在于 找图片。。。
|
|
返回顶楼 | |
发表时间:2011-10-24
朕看看怎么样
|
|
返回顶楼 | |
发表时间:2011-10-24
终于答完题了。下来看看
|
|
返回顶楼 | |
发表时间:2011-10-24
看下载数量,都很ms啊
|
|
返回顶楼 | |
发表时间:2011-10-24
还有,看lz取的名字removeClothForBeautyGirl,根本不是更衣,而是脱了就了事儿啊。
|
|
返回顶楼 | |
发表时间:2011-10-24
这个不错 看到这个我又有了学习动力了!
|
|
返回顶楼 | |
发表时间:2011-10-24
我的网速有些慢,努力学习一下!
|
|
返回顶楼 | |