MainActivity.java
package com.zhang.showPhoto; import android.app.ActionBar.LayoutParams; import android.app.Activity; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.view.animation.AnimationUtils; import android.widget.Button; import android.widget.ImageSwitcher; import android.widget.ImageView; import android.widget.ViewSwitcher.ViewFactory; public class MainActivity extends Activity { private int[] imagId=new int[]{ R.drawable.img01,R.drawable.img02,R.drawable.img03,R.drawable.img04, R.drawable.img05,R.drawable.img06,R.drawable.img07,R.drawable.img08, R.drawable.img09,R.drawable.img10 }; private int index=0; private ImageSwitcher imageSwitcher; private Button up,down; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); up=(Button) findViewById(R.id.bt1); down=(Button) findViewById(R.id.bt2); imageSwitcher=(ImageSwitcher) findViewById(R.id.imagSw1); imageSwitcher.setInAnimation(AnimationUtils.loadAnimation(this, android.R.anim.fade_in)); imageSwitcher.setOutAnimation(AnimationUtils.loadAnimation(this, android.R.anim.fade_out)); imageSwitcher.setFactory(new ViewFactory() { public View makeView() { ImageView imageView = new ImageView(MainActivity.this); imageView.setScaleType(ImageView.ScaleType.FIT_CENTER); imageView.setLayoutParams(new ImageSwitcher.LayoutParams( LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT )); return imageView; } }); imageSwitcher.setImageResource(imagId[index]); up.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if(index>0){ index--; }else{ index=imagId.length-1; } imageSwitcher.setImageResource(imagId[index]); } }); down.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if(index<imagId.length-1){ index++; }else{ index=0; } imageSwitcher.setImageResource(imagId[index]); } }); } }
main.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:background="@drawable/bg1" android:id="@+id/llayout" android:layout_width="fill_parent" android:layout_height="fill_parent" android:gravity="center" android:orientation="horizontal" > <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="上一张" android:id="@+id/bt1" /> <ImageSwitcher android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/imagSw1" android:layout_gravity="center" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="下一张" android:id="@+id/bt2" /> </LinearLayout>
再来看一段代码
// 获取图片的宽高 BitmapFactory.Options opt = new BitmapFactory.Options(); opt.inJustDecodeBounds = true; try{ bitmapIn = BitmapFactory.decodeFile(Puzzle.user.CUSTOM_IMAGE[customImage], opt); }catch(Exception e){ if(D) Log.d(TAG,"error"); return; } int in_w=opt.outWidth,in_h=opt.outHeight; // 获取imageview的尺寸 注意imageview的宽高比要与原图相同 否则需要另行计算 full_w = imageview.getWidth() full_h = getHeight() // 计算缩放比例 带有四舍五入 int Size_rate=(in_w*in_h*10)/(full_w*full_h); if(Size_rate>10){ Size_rate+=5; Size_rate/=10; }else{ Size_rate=1; } // 重新设置opt 读取图片文件 opt.inSampleSize=Size_rate; opt.inJustDecodeBounds = false; opt.inScaled = false; opt.outWidth=full_w; opt.outHeight=full_h; bitmapIn = BitmapFactory.decodeFile(Puzzle.user.CUSTOM_IMAGE[customImage], opt);}
本文向大家介绍jQuery图片轮播滚动切换代码分享,包括了jQuery图片轮播滚动切换代码分享的使用技巧和注意事项,需要的朋友参考一下 本文实例讲述了jQuery图片轮播滚动切换特效。分享给大家供大家参考,具体如下: jQuery图片轮播滚动切换代码是一款简单的jquery四张图片轮播滚动切换效果代码,实现过程很简单。 运行效果图:-------------------查看效果 下载源码-----
本文向大家介绍Python实现转换图片背景颜色代码,包括了Python实现转换图片背景颜色代码的使用技巧和注意事项,需要的朋友参考一下 在使用图片的时候有时候我们希望改变背景颜色,这样就只关注于图片本身。比如在连连看中就只有图片,而没有背景,其实我个人感觉有背景好看一点。 两种方法,思路一致: 法一: 法二: 以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持呐喊教程。
本文向大家介绍JavaScript图片轮播代码分享,包括了JavaScript图片轮播代码分享的使用技巧和注意事项,需要的朋友参考一下 为大家分享的JavaScript图片轮播代码如下 以上就是为大家分享的JavaScript图片轮播代码,希望大家可以喜欢。
本文向大家介绍图片旋转、鼠标滚轮缩放、镜像、切换图片js代码,包括了图片旋转、鼠标滚轮缩放、镜像、切换图片js代码的使用技巧和注意事项,需要的朋友参考一下 本文实例为大家展示了图片旋转、鼠标滚轮缩放、镜像、切换图片多重效果,提供了详细的代码,分享给大家供大家参考,具体内容如下 具体代码: abc.js 以上就是js代码实现图片旋转、鼠标滚轮缩放、镜像、切换图片等效果的代码,希望对大家学习javas
本文向大家介绍jquery图片倾斜层叠切换特效代码分享,包括了jquery图片倾斜层叠切换特效代码分享的使用技巧和注意事项,需要的朋友参考一下 本文实例讲述了jquery图片倾斜层叠切换特效代码。分享给大家供大家参考。具体如下: 这是一款基于jQuery.roundabout.js制作的CSS3图片倾斜层叠切换效果代码,很有层次感还可以左右切换,一款很清新的代码实例。 运行效果图:
本文向大家介绍python生成验证码图片代码分享,包括了python生成验证码图片代码分享的使用技巧和注意事项,需要的朋友参考一下 本文实例为大家分享了python生成验证码图片代码,分享给大家供大家参考,具体内容如下 基本上大家使用每一种网络服务都会遇到验证码,一般是网站为了防止恶意注册、发帖而设置的验证手段。其生成原理是将一串随机产生的数字或符号,生成一幅图片,图片里加上一些干扰象素(防止OC
本文向大家介绍jquery图片轮播特效代码分享,包括了jquery图片轮播特效代码分享的使用技巧和注意事项,需要的朋友参考一下 本文实例讲述了jquery图片轮播特效。分享给大家供大家参考。具体如下: 这是一款仿淘宝首页jquery轮播焦点图,基于jquery实现仿淘宝网首页正中间小焦点图特效。 运行效果图: -------------------查看效果 下载源码----------------
我必须将下面的Java代码转换成一个UML图,但是我不确定是否正确地完成了类之间的关联。请你告诉我UML图是否正确。