从零開始学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: ...
随机推荐
- SINGLETON(单例模式)---(孤独的人)
很多时候,我们都很彷徨,因为,在身边的朋友,很少. package patterns.createable.singleton; /** * 孤独的人啊 * 我为你写了一个类 * 这个类,在我们的程序 ...
- Delphi与C++的语法区别(六点区别) good
一.Delphi永远没办法在栈上创建一个对象 下面是一段常见的的Delphi代码,在过程的开头声明本过程所需要的全部局部变量: procedure Foo;var obj: TObject; //这句 ...
- 利用WinDbg找出程序崩溃的代码行号
之前碰到论坛里有几个好友,说程序不时的崩溃,什么xxoo不能read的! 如果光要是这个内存地址,估计你会疯掉~~ 所以分享一下基本的调试技巧,需要准备的工具有WinDbg + VC6.0, 下面是自 ...
- CMMI 是什么东西?
摘要: CMMI全称是Capability Maturity Model Integration,CMMI是个好东西来的,但行内人士对她的认识并不全面,甚至有种种的误解.尽管网上有很多CMM ...
- 看来IT技术与军事技术都是相通的——都是对新事物极为敏感的领域
这是读到这段时候的感想: 和海军中那些狂热的相信“皇军不可战胜”的大舰巨炮主义者们不同,山口对于与美国开战的主张是持坚定的反对态度的,和山本五十六都做过日本驻美武官的山口都认为一旦与美开战,日本或许能 ...
- java matlab混合编程之返回值Struct类型
java matlab混合编程的时候当返回值是Struct类型(matlab中的返回类型)如何来取得(java中)其值? 上网找,看到这个网页:http://www.mathworks.cn/cn/h ...
- 怎么获取Spring的ApplicationContext
在 WEB 开发中,可能会非常少须要显示的获得 ApplicationContext 来得到由 Spring 进行管理的某些 Bean, 今天我就遇到了,在这里和大家分享一下, WEB 开发中,怎么获 ...
- Bigcommerce: 给已完成购买的客户发送一封产品评论邮件,让客户直接进行产品评论
需求说明:进入后台的Order列表,更新订单状态:Awaiting Pickup后,就会给客户发送一封希望他们能进行评论的邮件.在邮件中展示该订单下的所有产品,每个产品都有一个评论的跳转链接,点击后直 ...
- 基于Andoird 4.2.2的Account Manager源代码分析学习:创建选定类型的系统帐号
AccountManager.addAccount() public AccountManagerFuture<Bundle> addAccount(final String accoun ...
- C++ Primer 学习笔记_79_模板与泛型编程 --模板编译模型
模板与泛型编程 --模板编译模型 引言: 当编译器看到模板定义的时候,它不马上产生代码.仅仅有在用到模板时,假设调用了函数模板或定义了模板的对象的时候,编译器才产生特定类型的模板实例. 一般而言,当调 ...