android ImageSwitcher的用法
来源:互联网 发布:激光去黑眼圈 知乎 编辑:程序博客网 时间:2024/05/29 15:52
本文详细讲解了图片切换器ImageSwitcher的用法
imageswitcher.xml:
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <ImageSwitcher android:id="@+id/imageswitcher" android:layout_width="wrap_content" android:layout_height="wrap_content" ></ImageSwitcher><LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal"> "<Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/previous" android:text="上一张" android:enabled="false" /><Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/next" android:text="下一张" android:enabled="true" /></LinearLayout></LinearLayout>
ImageSwitcherDemo.java:
package com.example.wenandroid;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.FrameLayout.LayoutParams;import android.widget.ImageSwitcher;import android.widget.ImageView;import android.widget.ViewSwitcher.ViewFactory;public class ImageSwitcherDemo extends Activity {private ImageSwitcher imageswitcher;private Button previous;private Button next;private int foot;private int imgRes[]=new int[]{R.drawable.first,R.drawable.second,R.drawable.third}; @Overrideprotected void onCreate(Bundle savedInstanceState) {// TODO Auto-generated method stubsuper.onCreate(savedInstanceState);setContentView(R.layout.imageswitcher);imageswitcher=(ImageSwitcher)findViewById(R.id.imageswitcher);previous=(Button)findViewById(R.id.previous);next=(Button)findViewById(R.id.next);//实现图片动画切换imageswitcher.setInAnimation(AnimationUtils.loadAnimation(this, android.R.anim.fade_in));imageswitcher.setOutAnimation(AnimationUtils.loadAnimation(this, android.R.anim.fade_out));imageswitcher.setFactory(new MyViewFactory());previous.setOnClickListener(new MyOnClickPrevious());next.setOnClickListener(new MyOnClickNext());}private class MyOnClickPrevious implements OnClickListener{@Overridepublic void onClick(View v) {// TODO Auto-generated method stubimageswitcher.setImageResource(imgRes[foot--]);checkButton();}}private class MyOnClickNext implements OnClickListener{@Overridepublic void onClick(View v) {// TODO Auto-generated method stubimageswitcher.setImageResource(imgRes[foot++]);checkButton();}}private void checkButton(){if(foot<imgRes.length-1){next.setEnabled(true);}else{next.setEnabled(false);}if(foot==0){previous.setEnabled(false);}else{previous.setEnabled(true);}}private class MyViewFactory implements ViewFactory{@Overridepublic View makeView() {// TODO Auto-generated method stubImageView imageview=new ImageView(ImageSwitcherDemo.this);imageview.setScaleType(ImageView.ScaleType.CENTER);imageview.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT));return imageview;}}}
- android ImageSwitcher的用法
- Android ImageSwitcher的用法!
- Android 中ImageSwitcher的最简单用法
- ImageSwitcher的用法
- ImageSwitcher的用法
- Android之ImageSwitcher,Gallery用法
- Android:ImageSwitcher 和 Gallery用法
- Android之Gallery和ImageSwitcher结合的用法
- Android的ImageSwitcher效果
- android ImageSwitcher的使用
- android ImageSwitcher的使用
- 【Android组件学习】ImageSwitcher+Gallery组合用法
- Android:Gallery,ImageSwitcher 和GridView用法
- Android的ImageSwitcher实现原理
- GridView和ImageSwitcher的功能和用法
- Android仿淘宝商品自动滚动 ImageSwitcher和TextSwitcher的用法
- Android ImageSwitcher
- Android ImageSwitcher
- mdev的使用以及mdev.conf的规则配置
- HDU 1405
- 机器学习理论与实战(七)Adaboost
- 机器学习理论与实战(八)回归
- POJ 2406 Power Strings KMP
- android ImageSwitcher的用法
- boost库在工作(34)网络服务端之四
- java设计模式---构建者模式
- Oracle索引优化规则
- APP 原型工具:Balsamiq Mockups
- mRemote Alternative
- vs2010连接mysql数据库进行增删改查操作
- 通过快速跟进与赶工追回项目进度
- VS2010添加配置文件