2

我有一个画廊查看器(按照教程),我需要在 5 秒后隐藏缩略图,并在用户触摸屏幕时再次显示它们。基本上,当缩略图被隐藏时,它只会显示已选择的图像。

我的代码如下:

package com.xs2theworld.sundio;

import android.app.Activity;
import android.content.Context;
import android.content.res.TypedArray;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.Gallery;
import android.widget.ImageView;

public class GalleryView extends Activity {
    Integer[] pics = { R.drawable.antartica1, R.drawable.antartica2, R.drawable.antartica3, R.drawable.antartica4, R.drawable.antartica5, R.drawable.antartica6, R.drawable.antartica7,
            R.drawable.antartica8, R.drawable.antartica9, R.drawable.antartica10 };
    ImageView imageView;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.gallery_view_layout);

        Gallery ga = (Gallery) findViewById(R.id.GalleryThumbnails);
        ga.setAdapter(new ImageAdapter(this));

        imageView = (ImageView) findViewById(R.id.GalleryImage);

        // We show the first image when creating the view gallery
        imageView.setScaleType(ImageView.ScaleType.CENTER);
        imageView.setImageResource(pics[0]);

        ga.setOnItemClickListener(new OnItemClickListener() {

            public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
                imageView.setScaleType(ImageView.ScaleType.CENTER);
                imageView.setImageResource(pics[arg2]);
            }
        });
    }

    public class ImageAdapter extends BaseAdapter {

        private Context ctx;
        int imageBackground;

        public ImageAdapter(Context c) {
            ctx = c;
            TypedArray ta = obtainStyledAttributes(R.styleable.Gallery1);
            imageBackground = ta.getResourceId(R.styleable.Gallery1_android_galleryItemBackground, 1);
            ta.recycle();
        }

        public int getCount() {

            return pics.length;
        }

        public Object getItem(int arg0) {
            return arg0;
        }

        public long getItemId(int arg0) {
            return arg0;
        }

        public View getView(int arg0, View arg1, ViewGroup arg2) {
            ImageView iv = new ImageView(ctx);
            iv.setImageResource(pics[arg0]);
            iv.setScaleType(ImageView.ScaleType.FIT_XY);
            iv.setLayoutParams(new Gallery.LayoutParams(200, 120));
            iv.setBackgroundResource(imageBackground);
            return iv;
        }
    }
}

我怎么能这样做?

提前非常感谢!

4

1 回答 1

1

使用 TimerTask 在 5 秒后在预定时间隐藏图库...

Timer timer = new Timer();

  timer.scheduleAtFixedRate(new TimerTask()
  {
     public void run()
     {
       //Do your task here
     }

  },delay,period);

或者你可以使用这个...

            View v = new View(this);
            v.postDelayed(new Runnable(){
                public void run() {
                    // TODO Auto-generated method stub
                    // Hide your Gallery here
                }
             }, (long) 5000.0);

希望它会帮助你。

于 2012-04-11T08:22:01.620 回答