从零開始学android<ImageSwitcher图片切换组件.二十六.>
|
1
|
public ImageSwitcher(Context context)
|
构造
|
创建ImageSwitcher对象
|
|
2
|
public void setFactory(ViewSwitcher.ViewFactory factory)
|
普通
|
设置ViewFactory对象。用于完毕两个图片切换时ViewSwitcher的转换操作
|
|
3
|
public void setImageResource(int resid)
|
普通
|
设置显示的图片资源ID
|
|
4
|
public void setInAnimation(Animation inAnimation)
|
普通
|
图片读取进ImageSwitcher时的动画效果
|
|
5
|
public void setOutAnimation(Animation outAnimation)
|
普通
|
图片从ImageSwitcher要消失时的动画效果
|
static interface ViewSwitcher.ViewFactory {
abstract View makeView() ;
class ViewFactoryImpl implements ViewFactory {
// 实例化图片显示
居中显示
// 自适应图片大小
// 定义组件
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" > <ImageSwitcher
android:id="@+id/imageSwitcher1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="114dp" >
</ImageSwitcher> <Button
android:id="@+id/button1"
style="? android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/button2"
android:layout_alignBottom="@+id/button2"
android:layout_marginRight="20dp"
android:layout_toLeftOf="@+id/imageSwitcher1"
android:text="上一张" /> <Button
android:id="@+id/button2"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toRightOf="@+id/imageSwitcher1"
android:text="下一张" /> </RelativeLayout>
package com.example.imageswitcher; import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
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 Button ButNext, ButPrevious;//初始化button
private ImageSwitcher imageSwitcher;//初始化组件
private int Images[] = { R.drawable.a1, R.drawable.a2, R.drawable.a3,
R.drawable.a4, R.drawable.a5, R.drawable.a6 };//设置图片数据
private int foot = 0;//设置角标 @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
imageSwitcher = (ImageSwitcher) this.findViewById(R.id.imageSwitcher1);//获得组件
ButNext = (Button) this.findViewById(R.id.button1);
ButPrevious = (Button) this.findViewById(R.id.button2);
imageSwitcher.setFactory(new Myfactory());//为组件设置组件工厂
imageSwitcher.setInAnimation(AnimationUtils.loadAnimation(
MainActivity.this, android.R.anim.fade_in));//设置图片进入动画
imageSwitcher.setOutAnimation(AnimationUtils.loadAnimation(
MainActivity.this, android.R.anim.fade_out));//设置图片离开动画
imageSwitcher.setImageResource(Images[foot++]);//设置图片 // button事件监听
ButNext.setOnClickListener(new View.OnClickListener() { @Override
public void onClick(View view) {
// TODO Auto-generated method stub
imageSwitcher.setImageResource(Images[foot++]);
MainActivity.this.CheckEnable();//设置button是否可用防止数组越界 }
});
// button事件监听
ButPrevious.setOnClickListener(new View.OnClickListener() { @Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
imageSwitcher.setImageResource(Images[foot--]);
MainActivity.this.CheckEnable();
}
}); } class Myfactory implements ViewFactory { @Override
public View makeView() {
// TODO Auto-generated method stub
ImageView image = new ImageView(MainActivity.this);//设置图片组件
image.setBackgroundColor(Color.GRAY);//设置对齐效果
image.setScaleType(ImageView.ScaleType.CENTER);//设置剧中
image.setLayoutParams(new ImageSwitcher.LayoutParams( // 自适应图片大小
LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT)); // 定义组件
return image;//返回图片 }
} public void CheckEnable() {
if (this.foot < this.Images.length - 1) {
this.ButNext.setEnabled(true); // button可用
} else {
this.ButNext.setEnabled(false); // button不可用
}
if (this.foot == 0) {
this.ButPrevious.setEnabled(false); // button不可用
} else {
this.ButPrevious.setEnabled(true); // button可用
} }
}
从零開始学android<ImageSwitcher图片切换组件.二十六.>的更多相关文章
- 从零開始学android<数据存储(1)SharedPreferences属性文件.三十五.>
在android中有五种保存数据的方法.各自是: Shared Preferences Store private primitive data in key-value pairs. 相应属性的键值 ...
- 第13章、布局Layouts之RelativeLayout相对布局(从零開始学Android)
RelativeLayout相对布局 RelativeLayout是一种相对布局,控件的位置是依照相对位置来计算的,后一个控件在什么位置依赖于前一个控件的基本位置,是布局最经常使用,也是最灵活的一种布 ...
- 从零開始学android<SeekBar滑动组件.二十二.>
拖动条能够由用户自己进行手工的调节,比如:当用户须要调整播放器音量或者是电影的播放进度时都会使用到拖动条,SeekBar类的定义结构例如以下所看到的: java.lang.Object ↳ an ...
- 从零開始学android<mediaplayer自带播放器(视频播放).四十九.>
MediaPlayer除了能够对音频播放之外,也能够对视频进行播放,可是假设要播放视频仅仅依靠MediaPlayer还是不够的.还须要编写一个能够用于视频显示的空间,而这块显示空间要求能够高速的进行G ...
- 从零開始学android<TabHost标签组件.二十九.>
TabHost主要特点是能够在一个窗体中显示多组标签栏的内容,在Android系统之中每一个标签栏就称为一个Tab.而包括这多个标签栏的容器就将其称为TabHost.TabHost类的继承结构例如以下 ...
- 从零開始学android<Menu菜单组件.三十.>
在Android系统之中.菜单一共同拥有三类:选项菜单(OptionsMenu).上下文菜单(ContextMenu)和子菜单(SubMenu). 今天我们就用几个样例来分别介绍下菜单的使用 acti ...
- 从零開始学android<RelativeLayout相对布局.十六.>
相对布局管理器指的是參考某一其它控件进行摆放,能够通过控制,将组件摆放在一个指定參考组件的上.下.左.右等位置,这些能够直接通过各个组件提供的属性完毕. 以下介绍一下各个方法的基本使用 No. 属性名 ...
- 从零開始学android<使用嵌套布局实现计算器界面.十七.>
所谓的嵌套布局就是在一个文件里嵌套多个布局文件 <span style="font-size:18px;"> <LinearLayout android:layo ...
- 从零開始学android<AnalogClock与DigitalClock时钟组件.三十一.>
这两个组件比較交单,大家看下会使用即可了 XML文件配置 <span style="font-size:18px;"><RelativeLayout xmlns: ...
随机推荐
- 学习VC MFC开发必须了解的常用宏和指令
1.#include指令 包含指定的文件 2.#define指令 预定义,通常用它来定义常量(包括无参量与带参量),以及用来实现那些“表面似和善.背后一长串”的宏,它本身并不在编译过程中进行,而 ...
- 使用简单的 5 个步骤设置 Web 服务器集群
通过在多个处理器之间分担工作负载并采用多种软件恢复技术,能够提供高度可用的环境并提高环境的总体 RAS(可靠性.可用性和可服务性).可以得到的好处包括:更快地从意外中断中恢复运行,以及将意外中断对终端 ...
- roll pitch yaw 的分别
原文地址:http://blog.sina.com.cn/s/blog_452706120100scwu.html yaw,pitch,roll这三个旋转的确切意思.如果有一个人站在(0,0,0)点, ...
- linux cent os putty 问题彻底解决办法
出现乱码的根本原因: linux系统和putty使用的编码格式不一致. 解决办法: 1.首先使用命令查看linux当前使用的是什么编码格式 echo $LANG 返回的结果有如下几种情况:1)zh_C ...
- 修改Tabhost样式和字体大小和居中显示
有时候我们的tabhost并不需要贴图,所以这个时候就必须把文字居中显示和设置大小了,代码如下 setContentView(R.layout.home_vzo_tabhost); ...
- 依赖注入(DI)有助于应用对象之间的解耦,而面向切面编程(AOP)有助于横切关注点与所影响的对象之间的解耦(转good)
依赖注入(DI)有助于应用对象之间的解耦,而面向切面编程(AOP)有助于横切关注点与所影响的对象之间的解耦.所谓横切关注点,即影响应用多处的功能,这些功能各个应用模块都需要,但又不是其主要关注点,常见 ...
- MSA2312 enclosure 闪断后
故障描述:由于电源原因,导致整个扩展柜闪断,硬盘全部为leftover状态. 存储划分配置:之前满配的一套MSA2312,划分为4个vd,后面两个vd无影响,前面2个VD都是一半在1号柜子,一半在2号 ...
- hdu 1240 Asteroids!(BFS)
题目链接:点击链接 简单BFS,和二维的做法相同(需注意坐标) 题目大意:三维的空间里,给出起点和终点,“O”表示能走,“X”表示不能走,计算最少的步数 #include <iostream&g ...
- hdoj 1258 SUM IT UP
程序的思想是:输入数据是,先使用快排对其从大到小进行排序,然后记录相同数据的个数,比如4 3 3 2 2 1 1,最后的数据变成4 3 2 1 ,并且同时数据的个数f[]变成1 2 2 2 然后就是遍 ...
- wwwtyro/cellophane
wwwtyro/cellophane A dead simple web terminal that gets all of the boilerplate out of the way and le ...