从零開始学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: ...
随机推荐
- TPL异步并行编程之取消任务
TPL异步并行编程之简单使用 在上篇随笔里面说明了Task的使用,仅仅是简单使用,有时候把一个任务交给Task去执行,但是呢还是要管理下,比如说:我要叫这个任务停止了,不做了,任务取消了,或者超时了 ...
- 【android】下载文件至本应用程序的file文件夹或者sdcard
一.推断是否有sdcard卡 //推断是否有SD卡 //ture:有SD卡 //false:没有SD卡 public boolean avaiableMedia(){ String status ...
- 9月mob(ShareSDK)活动预告,这个秋天非常热
9月秋天来临,广州的天气依旧非常热,广州的活动氛围更热~ 先有GMGC B2B对接会在广州创新谷,再有上方网TFC全球移动游戏开发人员大会来袭,游戏圈的火越烧越旺,成都GMGDC全球移动游戏开发人员大 ...
- 计算VMT的长度
function GetVirtualMethodCount(AClass: TClass): Integer; begin Result := (PInteger(Integer(AClass) + ...
- 搜索引擎爬虫蜘蛛的USERAGENT大全
搜索引擎爬虫蜘蛛的USERAGENT大全 搜索引擎爬虫蜘蛛的USERAGENT收集,方便制作采集的朋友. 百度爬虫 * Baiduspider+(+http://www.baidu.com/sea ...
- 理解Windows内核模式与用户模式
1.基础 执行 Windows 的计算机中的处理器有两个不同模式:"用户模式"和"内核模式". 依据处理器上执行的代码的类型,处理器在两个模式之间切换.应 ...
- 使用AjaxFileUpload.js实现文件异步上�
ajax是无法提交文件的,所以在上传图片并预览的时候,我们常常使用Ifame的方法实现看似异步的效果.可是这样总不是非常方便的,AjaxFilleUpload.js对上面的方法进行了一个包装,使得我们 ...
- ps中图层混合模式算法公式
网上已经有很多讲解ps的图层混合模式,有些不详细甚至是错误的,参考网上给出的公式及其自己在验证推倒的,给出27种的混合模式算法公式.也许存在一定的错误性,毕竟没有官方给出公式,只能说以供参考吧. 只考 ...
- 使用Python在2M内存中排序一百万个32位整数
译言网 | 使用Python在2M内存中排序一百万个32位整数 使用Python在2M内存中排序一百万个32位整数 译者:小鼠 发表时间:2008-11-13浏览量:6757评论数:2挑错数:0 作者 ...
- counting objects in class
參考文献:pgno=1">http://www.drdobbs.com/cpp/counting-objects-in-c/184403484? pgno=1