2012-02-15 41 views
0

我正在加载图像到图库视图,同时滚动图像,它似乎是一种摇摇欲坠或似乎卡住..我希望有一个平滑的滚动画廊。只有当我在10.1三星银河平板电脑中滚动时才会发生这种情况。请帮我解决这个问题。画廊滚动不光滑,是一种不稳定,而在平板电脑滚动

我用下面的代码

@Override 
    public View getView(int position, View convertView, ViewGroup parent) { 
     final int pos = position; 
     View retval = LayoutInflater.from(parent.getContext()).inflate(
       R.layout.horrizontallistitem, null); 
     final ImageView imgitem = (ImageView) retval 
       .findViewById(R.id.hlvItem); 
     try { 
      imgitem.setImageBitmap(CommonKeys 
        .getBitmapFromAsset("_images/" + dataObjects[pos] 
          + ".png")); 
     } catch (IOException e) { 
      // TODO Auto-generated catch block 
      e.printStackTrace(); 

     } 
     return retval; 
    } 
+0

这只发生在平板电脑上,而不是任何其他手机? – Maurice 2012-02-15 08:02:57

+0

是的,它只发生在平板电脑上 – cavallo 2012-02-15 08:26:19

回答

0

公共类LazyAdapter延伸BaseAdapter {

private Activity activity; 
private String[] data; 
private static LayoutInflater inflater=null; 
public ImageLoader imageLoader; 

public LazyAdapter(Activity a, String[] d) { 
    activity = a; 
    data=d; 
    inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
    imageLoader=new ImageLoader(activity.getApplicationContext()); 
} 

public int getCount() { 
    return data.length; 
} 

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

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

public View getView(int position, View convertView, ViewGroup parent) { 

    final int pos = position; 
    final ImageView imgitem=null; 
    View retval = convertView; 
    if(retval==null) 
    { 
      retval = LayoutInflater.from(parent.getContext()).inflate(
         R.layout.horrizontallistitem, null); 
      imgitem = (ImageView) retval 
         .findViewById(R.id.hlvItem); 
    } 
    imageLoader.DisplayImage(dataObjects[position], imgitem); 
    return retVal; 
} 

看到懒适配器implmentation通过以下链接:

https://github.com/thest1/LazyList/tree/master/src/com/fedorvlasov/lazylist

在这种FileCache, UrlConnection代码对你没有用处,但其余的代码可以实现您的目标

0
Create Image View at run time and add to Gallery.Your Activity Should implements 
ViewFactory  

private class ImageAdapter extends BaseAdapter{ 
    Context mContext; 
    private int itemBackground; 

    //private LayoutInflater layoutInflater; 
    public ImageAdapter(Context c){ 
     mContext = c; 
     //tempBitmap.clear(); 
     //tempBitmap=hashMap.get("page"+pageCount); 
     tempbitmap=new ArrayList<Bitmap>(); 
     tempbitmap.clear(); 
     int end=pageCount*5; 
     int start=end-5; 
     tempbitmap=bitmapArray.subList(start, end); 
     TypedArray attr = obtainStyledAttributes(R.styleable.HelloGallery); 
     itemBackground = attr.getResourceId(
       R.styleable.HelloGallery_android_galleryItemBackground, 0); 
     attr.recycle();  
     //layoutInflater = LayoutInflater.from(c); 
    } 

     @Override 
     public int getCount() { 
      // TODO Auto-generated method stub 
      return tempbitmap.size(); 
     } 

     @Override 
     public View getView(int position, View convertView, ViewGroup arg2) { 
      // TODO Auto-generated method stub 

      ImageView imageView; 
      if (convertView == null) { // if it's not recycled, initialize some attributes 
       imageView = new ImageView(mContext); 
       imageView.setLayoutParams(new Gallery.LayoutParams(170,grid_main.getHeight())); 
       imageView.setScaleType(ImageView.ScaleType.FIT_XY); 
       imageView.setBackgroundResource(itemBackground); 

       //imageView.setPadding(8,8,8,8); 
      } else { 
       imageView = (ImageView) convertView; 
      } 
      imageView.setImageBitmap(tempbitmap.get(position)); 
      return imageView; 
     } 

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

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

     } 

     } 


    @Override 
    public View makeView() { 
     // TODO Auto-generated method stub 
     ImageView imageView = new ImageView(this); 
     imageView.setScaleType(ImageView.ScaleType.FIT_CENTER); 
     imageView.setLayoutParams(new 
       ImageSwitcher.LayoutParams(
         LayoutParams.FILL_PARENT, 
         LayoutParams.FILL_PARENT)); 
     imageView.setBackgroundColor(0xFF000000); 
     return imageView; 
    }