zoukankan      html  css  js  c++  java
  • ImageSwitcher 练习(android)

    ImageSwitch 需要一个 ViewFactory 接口方法,返回一个 ImageView 对像,同时指定 setFactory 方法

    其中试了试用 ImageView 实现 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" >

        <TextView
            
    android:layout_width="fill_parent"
            android:layout_height
    ="wrap_content"
            android:text
    ="@string/hello" />
         <ImageView 
             
    android:id="@+id/iv"
             android:layout_width
    ="wrap_content"
             android:layout_height
    ="wrap_content"
             
    />
         <Button 
             
    android:id="@+id/btn"
             android:layout_width
    ="wrap_content"
             android:layout_height
    ="wrap_content"
             android:text
    ="切换图片"
             
    />
         
         <ImageSwitcher 
             
    android:id="@+id/imageswitch"
             android:layout_width
    ="wrap_content"
             android:layout_height
    ="wrap_content"  
             
    ></ImageSwitcher>
         <Button 
             
    android:id="@+id/btn2"
             android:layout_width
    ="wrap_content"
             android:layout_height
    ="wrap_content"
             android:text
    ="切换图片2"
             
    />
    </LinearLayout>

    java代码

    package zziss.android.imageswitchtest;

    import android.app.Activity;
    import android.os.Bundle;
    import android.view.View;
    import android.widget.Button;
    import android.widget.ImageSwitcher;
    import android.widget.ImageView;
    import android.widget.ViewSwitcher.ViewFactory;

    public class ImageSwitchTestActivity extends Activity implements ViewFactory {
        /** Called when the activity is first created. */
        private ImageView iv;
        private ImageSwitcher imw;
        private Button    btn;
        private Button    btn2;
        private int       i;
        private int       index;
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
            iv = (ImageView)this.findViewById(R.id.iv);
            btn = (Button)this.findViewById(R.id.btn);
            btn2 = (Button)this.findViewById(R.id.btn2);
            
            imw  = (ImageSwitcher)this.findViewById(R.id.imageswitch);
            imw.setFactory(this);
            i = 0;
            index =0;
            btn.setOnClickListener(new View.OnClickListener() {
                
                @Override
                public void onClick(View v) {
                    // TODO Auto-generated method stub
                    /*if (i==0)
                    {
                        iv.setImageResource(R.drawable.png1410);
                        i=1;
                    }
                    else
                    {
                        iv.setImageResource(R.drawable.png1411);
                        i=0;
                    }
    */
                    if (index>=3)
                        index = 0;
                    iv.setImageResource(imagelist[index]);
                    index++;
                }
            });
            
            btn2.setOnClickListener(new View.OnClickListener() {
                
                @Override
                public void onClick(View v) {
                    // TODO Auto-generated method stub
                    if (index>=3)
                        index = 0;
                    imw.setImageResource(imagelist[index]);
                    index++;
                }
            });
            
        }
        
        private static int[] imagelist =
            {
                R.drawable.png1410,
                R.drawable.png1411,
                R.drawable.png1412
            };
        @Override
        public View makeView() {
            // TODO Auto-generated method stub
            return new ImageView(this);
        }
    }
  • 相关阅读:
    PHP把下划线分隔命名的字符串与驼峰式命名互转
    Cocos2d-JS/Ajax用Protobuf与NodeJS/Java通信
    gulp 实现 js、css,img 合并和压缩
    转:入门Webpack,看这篇就够了
    微信开发教程:用户账号绑定到微信公众号的方法分享
    C#RSA算法实现+如何将公钥为XML格式转为PEM格式,给object-C使用
    php使用openssl进行Rsa长数据加密(117)解密(128) 和 DES 加密解密
    Windows下将nginx安装为服务运行
    转载:Centos7 从零编译配置Memcached
    转载:Centos7 从零编译Nginx+PHP+MySql 二
  • 原文地址:https://www.cnblogs.com/zziss/p/2313797.html
Copyright © 2011-2022 走看看