zoukankan      html  css  js  c++  java
  • Gallery和IamgeSwitcher协作幻灯片效果

    Gallery和IamgeSwitcher协作幻灯片效果

     

      今天学习了Android的Gallery,根据自己的喜好做了一个NBA球星的幻灯片,也算是一边学习,一边自娱自乐吧。。。

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    package com.test.gallery;
     
    import android.app.Activity;
    import android.content.res.TypedArray;
    import android.os.Bundle;
    import android.view.View;
    import android.view.ViewGroup;
    import android.view.ViewGroup.LayoutParams;
    import android.view.animation.AnimationUtils;
    import android.widget.AdapterView;
    import android.widget.AdapterView.OnItemClickListener;
    import android.widget.BaseAdapter;
    import android.widget.Gallery;
    import android.widget.ImageSwitcher;
    import android.widget.ImageView;
    import android.widget.ViewSwitcher.ViewFactory;
     
    public class TestGallleryActivity extends Activity {
        int[] imgIds = new int[]{R.drawable.a1,R.drawable.a2,R.drawable.a3,R.drawable.a4,
                R.drawable.a5,R.drawable.a6,R.drawable.a7,R.drawable.a8,
                R.drawable.a9,R.drawable.a10,R.drawable.a11,R.drawable.a12,
                R.drawable.a13,R.drawable.a14,R.drawable.a15,R.drawable.a16};
         
        /** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
             
            final ImageSwitcher switcher = (ImageSwitcher)findViewById(R.id.switcher);
            switcher.setInAnimation(AnimationUtils.loadAnimation(this, android.R.anim.fade_in));
            switcher.setOutAnimation(AnimationUtils.loadAnimation(this, android.R.anim.fade_out));
            switcher.setFactory(new ViewFactory() {
                 
        public View makeView() {
        ImageView img1 = new ImageView(TestGallleryActivity.this);
        img1.setBackgroundColor(0xff0000);          
        img1.setScaleType(ImageView.ScaleType.FIT_CENTER);
        img1.setLayoutParams(new ImageSwitcher.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
                     
                return img1;
                }
            });
            
            BaseAdapter adapter = new BaseAdapter(){
     
        public int getCount() {
                    // TODO Auto-generated method stub
            return imgIds.length;
                }
     
          public Object getItem(int position) {
                    // TODO Auto-generated method stub
            return position;
                }
     
        public long getItemId(int position) {
                    // TODO Auto-generated method stub
            return position;
                }
     
        public View getView(int position, View convertView, ViewGroup parent) {
                    // TODO Auto-generated method stub
            ImageView img2 = new ImageView(TestGallleryActivity.this);
        img2.setImageResource(imgIds[position]);
        img2.setScaleType(ImageView.ScaleType.FIT_XY);
            img2.setLayoutParams(new Gallery.LayoutParams(75,100));
            TypedArray typedArray = obtainStyledAttributes(R.styleable.Gallery);
            img2.setBackgroundResource(typedArray.getResourceId(R.styleable.Gallery_android_galleryItemBackground,0));
                return img2;
                }};
                 
                Gallery gallery = (Gallery)findViewById(R.id.gallery);
                gallery.setAdapter(adapter);
                gallery.setOnItemClickListener(new OnItemClickListener(){
     
        public void onItemClick(AdapterView<?> arg0, View arg1,int arg2, long arg3) {
         
            switcher.setImageResource(imgIds[arg2]);
                    }});
        }
    }
  • 相关阅读:
    贪吃蛇—C—基于easyx图形库(上):基本控制函数实现 画图程序
    ubuntu之路——day7.3 normalizing input(加快迭代速度)
    ubuntu之路——day7.2 regularization
    ubuntu之路——day7.1 衡量模型好坏的因素偏差和方差bias&variance 以及在深度学习中的模型优化思路
    ubuntu之路——day6(今天对数据集的建立有了更深的体会)
    ubuntu之路——day5(今天看了浅层神经网络的数学推导过程)
    ubuntu之路——day4(今天主要看了神经网络的概念)
    python format 时间格式
    ubuntu之路——day3(本来打算做pytorch的练习 但是想到前段时间的数据预处理的可视化分析 就先总结一下)
    ubuntu之路——day2
  • 原文地址:https://www.cnblogs.com/Leo_wl/p/2416022.html
Copyright © 2011-2022 走看看