android图片转换器示例
发布时间:2022-02-16 14:27:01
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>


猜你喜欢
- public class MainActivity extends Activity { @Override protected void
- 这篇山寨一个新版QQ的列表滑动删除,上篇有说到QQ的滑动删除,推测原理就是ListView本身每个item存在一个Button,只不过普通的
- 前言这个题目可能取得不大好,想了很久没想出更合适的了。在android开发webview的时候,有的时候后台不一定给的就是一个url,而是把
- 对于之前最火的无外乎集五福了,而五福除了加十个好友获得外,最直接的途径就是支付宝的咻一咻了。那么咻一咻具体有哪些实现方式呢?下面我们将一一介
- 本文实例讲述了Java Scanner类用法及nextLine()产生的换行符问题。分享给大家供大家参考,具体如下:分析理解:Scanner
- 在使用AndroidNDK开发的时候有个事情是很烦人的,那就是创建本地代码文件夹,生成本地代码文件和创建本地代码的编译文件。特别是实现本地方
- Android 自定义 Toast 显示时间实现代码:package com.wm.realname.util;import android
- 水平的ListView-HorizontalListView的使用Android中ListView默认的是竖直方向的滑动,由于项目的需求,需
- C# 中同样支持多维数组(也可称为矩形数组),它可以是二维的,也可以是三维的,多维数组中的数据以类似表格(行、列)的形式存储,因此也被称为矩
- 大白话讲解:从广义上 Spring 注解可以分为两类:一类注解是用于注册 Bean假如 IoC 容器是一间空屋子,首先这间空屋子啥都没有,我
- 前言复习一下spring实现IOC的源码流程准备工作:强烈建议大家从git上拉取spring源码来学习Spring源码。因为里面相较于IDE
- 引言Spring Boot的一个便捷功能是外部化配置,可以轻松访问属性文件中定义的属性。本文将详细介绍@ConfigurationPrope
- 两种方式:1. String str = "123 456 789 111";String [] strArray =
- 本文实例为大家分享了C#实现计算器功能的具体代码,供大家参考,具体内容如下代码:Random rad = new Random(); //
- mybatis-spring:@MapperScan注解在demo: springboot+mybatis的示例中,dao层接口使用了注解@
- 通常我们在看一些源码时,发现全是T、?,晕乎乎的:sob:。于是,把泛型掌握好十分重要!什么是泛型Java 泛型(generics)是 JD
- IO的本质IO的作用就是从外部系统读取数据到java程序中,或者把java程序中输出的数据写回到外部系统。这里的外部系统可能是磁盘,网络流等
- @RequestBody与post请求的关系@RequestBody主要用来接收前端传递给后端的json字符串中的数据的(请求体中的数据的)
- 1、前期准备需要在Manifest中添加相关权限<uses-permission android:name="android
- 本文实例讲述了C#使用iTextSharp设置PDF所有页面背景图功能的方法。分享给大家供大家参考。具体如下:在生成PDF 的时候,虽然可以