如何使用齐射将多个图像存储在Array中和单个ImageView上 [英] how to store multiple images store in Array and on single ImageView using volley
本文介绍了如何使用齐射将多个图像存储在Array中和单个ImageView上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我只想使用volley
将多张照片放在一个imageView
中,每3秒自动更改/闪烁一次.不是ViewPager/slider
.
I just want to put multiple photos in a single imageView
using the volley
that is going to change/blinks automatically every 3 seconds. it is not ViewPager/slider
.
int[] imageArray;
ImageView blinkImage;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
// Inflate the layout for this fragment
view = inflater.inflate(R.layout.fragment_home, container,false);
blinkImage=(ImageView)view.findViewById(R.id.hardImage);
final Handler handler = new Handler();
Runnable runnable = new Runnable() {
int i = 0;
public void run() {
blinkImage.setImageResource(imageArray[i]);
i++;
if (i > imageArray.length - 1) { i = 0; }handler.postDelayed(this,3000);
}
};
handler.postDelayed(runnable,200);
return view;
}
推荐答案
使用带有处理程序的rotateImage函数来确定间隔
use rotateImage function with a handler to determine the interval
private ImageView image1;
private int[] imageArray;
private int currentIndex;
private int startIndex;
private int endIndex;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
image1 = (ImageView)findViewById(R.id.imageView1);
imageArray = new int[8];
imageArray[0] = R.drawable.one;
imageArray[1] = R.drawable.two;
imageArray[2] = R.drawable.three;
imageArray[3] = R.drawable.four;
imageArray[4] = R.drawable.five;
imageArray[5] = R.drawable.six;
imageArray[6] = R.drawable.seven;
imageArray[7] = R.drawable.eight;
startIndex = 0;
endIndex = 7;
nextImage();
}
public void nextImage(){
image1.setImageResource(imageArray[currentIndex]);
Animation rotateimage = AnimationUtils.loadAnimation(this, R.anim.custom_anim);
image1.startAnimation(rotateimage);
currentIndex++;
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
if(currentIndex>endIndex){
currentIndex--;
previousImage();
}else{
nextImage();
}
}
},1000); // here 1000(1 second) interval to change from current to next image
}
public void previousImage(){
image1.setImageResource(imageArray[currentIndex]);
Animation rotateimage = AnimationUtils.loadAnimation(this, R.anim.custom_anim);
image1.startAnimation(rotateimage);
currentIndex--;
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
if(currentIndex<startIndex){
currentIndex++;
nextImage();
}else{
previousImage(); // here 1000(1 second) interval to change from current to previous image
}
}
},1000);
}
或者您可以像这样构建自定义帧动画
or you can build a custom frame animation like this
AnimationDrawable animation = new AnimationDrawable();
animation.addFrame(getResources().getDrawable(R.drawable.image1), 100);
animation.addFrame(getResources().getDrawable(R.drawable.image2), 500);
animation.addFrame(getResources().getDrawable(R.drawable.image3), 300);
animation.setOneShot(false);
ImageView imageAnim = (ImageView) findViewById(R.id.img);
imageAnim.setBackgroundDrawable(animation);
// start the animation!
animation.start()
这篇关于如何使用齐射将多个图像存储在Array中和单个ImageView上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文