मैं GridView
में एनीमेशन का उपयोग करके प्रदर्शित करना चाहता हूं। मैं उन्हें प्रदर्शित कर सकता हूं और एनीमेशन को सही तरीके से लागू कर सकता हूं।छवियों को प्रदर्शित करें एनीमेशन समस्या
लेकिन समस्या यह है कि, यदि मैं ImageView1 पर एनीमेशन लागू करता हूं और फिर ImageView2 (ImageView1 पर एनीमेशन समाप्त होने से पहले) तो ImageView1 पर एनीमेशन बाधित हो जाता है और ImageView1 सीधे अंतिम स्थिति पर सेट हो जाता है।
ध्यान दें कि मैं ThreadPoolExecutor
का उपयोग करके 2 थ्रेड के साथ छवि डाउनलोड करता हूं। जब भी कोई छवि डाउनलोड हो जाती है, तो मैं addImage(image)
ImageAdapter
से नीचे की विधि को कॉल करता हूं जो बदले में GridView
और GridView
में छवि को नवीनतम छवियों को प्रदर्शित करने के लिए ताज़ा किया जाता है। और यहां, प्रतिपादन करते समय, नई छवि एनीमेशन के साथ प्रदर्शित होती है और यह एनीमेशन (मुझे लगता है) वर्तमान में एनिमेटिंग छवियों की एनीमेशन को बाधित करता है।
ImageAdapter:
public class ImageAdapter extends BaseAdapter {
private Context mContext;
private List<Bitmap> images;
private ArrayList<Integer> colors;
private boolean[] alreadyLoadedIndexes;
Animation animation;
AnimatorSet animator;
public void addImage(Bitmap img) {
images.add(img);
notifyDataSetChanged();
}
public void setAnimation(Animation animation) {
this.animator = null;
this.animation = animation;
}
public void setAnimator(AnimatorSet animation) {
this.animation = null;
this.animator = animation;
}
public void resetImages() {
images.clear();
notifyDataSetChanged();
alreadyLoadedIndexes = null;
alreadyLoadedIndexes = new boolean[20];
}
// Constructor
public ImageAdapter(Context c) {
mContext = c;
images = new ArrayList<Bitmap>();
colors = new ArrayList<Integer>();
colors.add(Color.CYAN);
colors.add(Color.BLUE);
colors.add(Color.GRAY);
colors.add(Color.YELLOW);
colors.add(Color.MAGENTA);
alreadyLoadedIndexes = new boolean[20];
}
@Override
public int getCount() {
return 20;
}
@Override
public Object getItem(int position) {
return 20;
}
@Override
public long getItemId(int position) {
return 0;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ImageView imageView = new ImageView(mContext);
imageView
.setBackgroundColor(colors.get((int) ((Math.sqrt(position) + 2 * position) % 5)));
// If image at index 'position' is available
if (images.size() > position) {
// If loading this image first time then only apply animation
if (!alreadyLoadedIndexes[position]) {
// If animation is specified
if (this.animation != null) {
imageView.setImageBitmap(images.get(position));
imageView.startAnimation(animation);
}
// If animator set is specified
else if (this.animator != null) {
imageView.setImageBitmap(null);
imageView.setBackgroundColor(colors.get((int) ((Math
.sqrt(position) + 2 * position) % 5)));
animator.setTarget(imageView);
animator.start();
Log.e("", "setting image after " + animator.getDuration()
/2);
new Handler().postDelayed(
new runnable(imageView, images.get(position)), 500);
} else {
// Use default animation if nothing is specified.
imageView.setImageBitmap(images.get(position));
animation = AnimationUtils.loadAnimation(mContext,
R.anim.fade_in);
imageView.startAnimation(animation);
}
} else {
imageView.setImageBitmap(images.get(position));
}
alreadyLoadedIndexes[position] = true;
}
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
imageView.setLayoutParams(new GridView.LayoutParams(150, 150));
return imageView;
}
class runnable implements Runnable {
ImageView image;
Bitmap bitmap;
public runnable(ImageView img, Bitmap bitmap) {
this.image = img;
this.bitmap = bitmap;
}
@Override
public void run() {
Log.e("", "setting image.");
image.setImageBitmap(bitmap);
}
}
}
लेकिन जब मेरे पास, उदाहरण के लिए, 50 छवियों को प्रदर्शित करने के लिए और यदि मैं 'छवि को सूचित करेंडेटाट चेंज()' कॉल करने से पहले पूरा करने के लिए प्रत्येक छवि की एनीमेशन की प्रतीक्षा करूंगा तो सभी छवियों को लोड करने में लगभग 15-20 सेकंड लगेंगे। – Geek
@Akash तो कृपया बताएं कि आप इसे कैसे व्यवहार करना चाहते हैं? –
मैं सभी छवियों को एनीमेशन पूर्ण करना चाहता हूं लेकिन छवि लोडिंग समय को यथासंभव कम रखना चाहता हूं। समवर्ती छवि एनिमेशन वह है जो मैं एक-एक करके खोजता हूं। – Geek