gpt4 book ai didi

Android:倒计时后隐藏图库

转载 作者:行者123 更新时间:2023-11-29 02:05:52 25 4
gpt4 key购买 nike

我有一个图库查看器(遵循 this 教程),我需要在 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;
}
}
}

我该怎么做?

提前致谢!

最佳答案

使用 TimerTask 在 5 秒后的预定时间隐藏 Gallery...

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);

希望对您有所帮助。

关于Android:倒计时后隐藏图库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10101857/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com