去年有一段时间有一个应用下载量很高,都是男同志的功劳,现在又出了第二版,第二层我们就来实现一下《帮美女更衣》这个应用,很多男生应该熟悉这个应用了吧,这里我就不解释里面的内容了,呵呵。

先看看我们要实现的效果:

             (惨不忍睹!做好后大家去挖剩下的吧)

先看看布局文件activity_main.xml

<?xml version="1.0" encoding="UTF-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="fill_parent"android:layout_height="fill_parent" ><ImageSwitcherandroid:id="@+id/image_switcher"android:layout_width="fill_parent"android:layout_height="wrap_content"android:layout_alignParentLeft="true"android:layout_alignParentTop="true" /><Galleryandroid:id="@+id/gallery"android:layout_width="fill_parent"android:layout_height="80.0dip"android:layout_alignParentBottom="true"android:layout_alignParentLeft="true"android:background="#55000000"android:gravity="center_vertical"android:spacing="15.0dip" /></RelativeLayout>

ImageSwitcher继承自ViewSwitcher,重写了showNext()、showPrevious()方法。

使用ImageSwithcer的步骤如下:

1、为ImageSwitcher提供一个ViewFactory,该ViewFactory会有一个makeView()方法来生成View组件,这个组件必须是ImageView.

2、切换图片时只需要调用 setImageDrawable(Drawable drawable)方法、setImageResource(int resid)方法或setImageURI(Uri uri).

package com.example.mygrilproject;import android.app.Activity;
import android.content.Context;
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.ViewSwitcher.ViewFactory;public class MainActivity extends Activity implements ViewFactory{private ImageSwitcher is;private Gallery gallery;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);//获取ImageSwitcher对象is = (ImageSwitcher)findViewById(R.id.image_switcher);is.setFactory(this);//获取gallery对象gallery = (Gallery)findViewById(R.id.gallery);//设置适配器gallery.setAdapter(new ImageAdapter(MainActivity.this));//设置监听gallery.setOnItemSelectedListener(new OnItemSelectedListener() {@Overridepublic 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();}//更换ImageSwitcher中的图片is.setImageResource(drawableId);}@Overridepublic void onNothingSelected(AdapterView<?> parent) {}  });is.setOnClickListener(new OnClickListener() {@Overridepublic void onClick(View v){}});}//设置图片切换的动画效果@Overridepublic 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;}private class ImageAdapter extends BaseAdapter {private Context mContext;public ImageAdapter(Context c){mContext = c;}@Overridepublic int getCount() {return 11;//11张图片}@Overridepublic Object getItem(int position) {return position;}@Overridepublic long getItemId(int position) {return position;}@Overridepublic 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;}}}

运行效果:

下一篇我们再来看看如何撕衣服,呵呵

源代码下载:http://download.csdn.net/detail/lxq_xsyu/7014543

转载于:https://www.cnblogs.com/lanzhi/p/6469143.html

是男人就下100层【第二层】——帮美女更衣(1)相关推荐

  1. 是男人就下100层【第四层】——Crazy贪吃蛇(2)

    在上一篇<是男人就下100层[第四层]--Crazy贪吃蛇(1)>中我们让贪吃蛇移动了起来,接下来我们来实现让贪吃蛇能够绕着手机屏幕边线移动而且能够改变方向 一.加入状态并改动代码 首先我 ...

  2. 是男人就下100层【第五层】——2048游戏从源码到发布市场

    上一篇<是男人就下100层[第五层]--换肤版2048游戏>中阳光小强对2048游戏用自己的方式进行了实现,并分享了核心源码,这一篇阳光小强打算将该项目的所有源代码公开并结合这个实例在这篇 ...

  3. 是男人就下100层【第一层】——高仿微信界面(8)

    上一篇<是男人就下100层[第一层]--高仿微信界面(7)>中我们实现了下弹式菜单,这一篇我们来看看如何实现微信中的摇一摇功能. 首先我们来布局我们的摇一摇界面 布局文件如下: <? ...

  4. 是男人就下100层【第一层】——高仿微信界面(2)

    接着上一篇<是男人就下100层[第一层]--高仿微信界面(1)>,本打算实现上一篇文章中的第二个界面,这一篇先来实现一下登陆界面吧,接下来我们来开始登录界面的制作. 界面布局文件: < ...

  5. 是男人就下100层【第一层】——高仿微信界面(1)

    从今天开始将进行一个特别有趣且有意义的专栏<是男人就下100层>,计划对市面上比较火的应用进行高度仿照,并将开发过程贴出来,和大家交流和分享.由于时间关系可能进度会比较缓慢,但是任何事情如 ...

  6. 【编程马拉松】【026-是男人就下100层】

    [编程马拉松算法目录] [026-是男人就下100层][工程下载>>>] 1 题目描述 相信大家都听说过"是男人就下100层"系列游戏,游戏中包括多个长度和高度各 ...

  7. 是男人就下100层【第五层】——换肤版2048游戏

    ---------------------------------------------------------------------------------------------------- ...

  8. Cocos2d-x 版本小游戏 《是男人就下100层》 项目开源

    Cocos2d-x 版本小游戏 <是男人就下100层> 项目开源 原文:Cocos2d-x 版本小游戏 <是男人就下100层> 项目开源 这个是很久就开始动手写的一个小游戏了, ...

  9. 是男人就下100层【第五层】——2048游戏从源代码到公布市场

    上一篇<是男人就下100层[第五层]--换肤版2048游戏>中阳光小强对2048游戏用自己的方式进行了实现,并分享了核心源码,这一篇阳光小强打算将该项目的全部源码公开并结合这个实例在这篇文 ...

  10. 是男人就下100层【第一层】——高仿微信界面(4)

    上一篇<是男人就下100层[第一层]--高仿微信界面(3)>中我们完成了登录,这一篇看完成登录后的一个短暂加载和引导界面. 加载界面: <RelativeLayout xmlns:a ...

最新文章

  1. BootstrapTable
  2. 天津教师招聘考试计算机真题及答案,天津教师招聘考试真题五(含答案)
  3. 面向对象特征:封装、多态 以及 @propetry装饰器
  4. 在BurpSuite中安装Jython环境
  5. Yii 2 美化 url
  6. 织梦dedecms内核自适应移动POS机刷卡机招商加盟企业网站源码
  7. 额外sql使用什么封装_为什么建立社区值得付出额外的努力
  8. 【Godot】项目结构设计
  9. SAP ABAP BAPI_MATERIAL_AVAILABILITY 查询可用库存
  10. 农场买了一羊,第一年是小羊,第二年底生一只,第三年不生,第四年底再生一只,第五年死掉
  11. phpnow mysql_PHPNOW中如何建立MYSQL数据库连接?
  12. Docker Jenkins 连接agent:SSH key presented by the remote host does not match the key saved in the Know
  13. 2013中国Linux内核开发者大会亮点汇总
  14. Adobe Premiere Pro cs6 精简版 0xc000007b 应用程序无法正常启动
  15. oracle表空间不足影响,oracle表空间不足
  16. 塔菲尔曲线如何分析_Tafel曲线是做什么的
  17. python快速入门精讲_Python快速入门精讲
  18. 使用VMware通过vmdk文件创建XP虚拟机
  19. Android-ubuntu配置
  20. 缺陷检测中的分类、检测与分割网络

热门文章

  1. Android简单实现百度地图显示及定位
  2. 那些适用于跨境电商的ERP系统
  3. 普林斯顿微积分读本篇十七:数列和级数,泰勒定理
  4. 学生优化--文本框限制
  5. NanoPC-T4 RK3399和PC局域网络传输摄像头视频python
  6. 常微分方程组及高阶常微分方程的数值解法
  7. 微分方程数值解法结语
  8. 分别用精密星历和广播星历计算卫星坐标 -- 对 GNSS 第一次编程的总结
  9. Head First设计模式读书笔记一 策略模式
  10. foobar2000 for mac(经典音乐播放器)