zoukankan      html  css  js  c++  java
  • ImageSwitcher 与Gallery的应用

    private int[] imgId=new int[]{R.drawable.file1,R.drawable.file2,R.drawable.file3,R.drawable.file4};   //添加图片数组
    private int position=0;
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    final ImageSwitcher mySwitcher=(ImageSwitcher)findViewById(R.id.mySwitcher);
    mySwitcher.setFactory(new ViewFactory(){
    public View makeView(){
    ImageView imageView=new ImageView(MainActivity.this);
    imageView.setLayoutParams(new ImageSwitcher.LayoutParams(240,240));
    imageView.setScaleType(ScaleType.FIT_XY);
    return imageView;
    }
    });
    //mySwitcher.setInAnimation(AnimationUtils.loadAnimation(context, id))
    mySwitcher.setImageResource(imgId[0]);
    /* mySwitcher.setOnClickListener(new OnClickListener(){
    public void onClick(View v) {
    position++;
    mySwitcher.setImageResource(imgId[position%imgId.length]);
    }
    }); */

    Gallery myGallery=(Gallery)findViewById(R.id.myGallery);
    BaseAdapter baseAdapter=new BaseAdapter() {

    public View getView(int position, View convertView, ViewGroup parent) {
    ImageView imageView=new ImageView(MainActivity.this);
    imageView.setScaleType(ScaleType.FIT_XY);
    imageView.setLayoutParams(new Gallery.LayoutParams(60,70));
    imageView.setImageResource(imgId[position % imgId.length]);
    return imageView;
    }

    @Override
    public long getItemId(int position) {
    // TODO Auto-generated method stub
    return position;
    }

    @Override
    public Object getItem(int position) {
    // TODO Auto-generated method stub
    return imgId[position];
    }

    @Override
    public int getCount() {
    // TODO Auto-generated method stub
    //return imgId.length;
    return Integer.MAX_VALUE;
    }
    };
    myGallery.setAdapter(baseAdapter);
    myGallery.setOnItemSelectedListener(new OnItemSelectedListener() {

    public void onItemSelected(AdapterView<?> parent, View view,
    int position, long id) {
    mySwitcher.setImageResource(imgId[position%imgId.length]);

    }


    public void onNothingSelected(AdapterView<?> parent) {
    // TODO Auto-generated method stub

    }
    });
    }

  • 相关阅读:
    windows 上安装redis和windows上redis与php扩展
    mysql存储过程详细讲解及完整实例下载
    html模板生成静态页面及模板分页处理
    php中自动加载类_autoload()和spl_autoload_register()实例详解
    php+mysql事务处理例子详细分析实例
    git学习和常用命令
    block理解
    oc中数组,字典,集合使用的备忘录
    oc log的记录 宏的正确姿势
    swift中的optional
  • 原文地址:https://www.cnblogs.com/liumin-txgt/p/12766158.html
Copyright © 2011-2022 走看看