Android 图库滚动不平滑,在平板电脑中滚动时有点摇晃

Android 图库滚动不平滑,在平板电脑中滚动时有点摇晃,android,scroll,gallery,smooth-scrolling,Android,Scroll,Gallery,Smooth Scrolling,我正在将图像加载到gallery视图中,当滚动图像时,它似乎有点摇晃或卡住了。。我希望有一个平滑的滚动画廊。只有当我在10.1三星galaxy平板电脑上滚动时才会出现这种情况。请帮我解决这个问题 我使用下面的代码 @Override public View getView(int position, View convertView, ViewGroup parent) { final int pos = position; View retval

我正在将图像加载到gallery视图中,当滚动图像时,它似乎有点摇晃或卡住了。。我希望有一个平滑的滚动画廊。只有当我在10.1三星galaxy平板电脑上滚动时才会出现这种情况。请帮我解决这个问题

我使用下面的代码

   @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;
    }

公共类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;
}
请通过以下链接查看惰性适配器实现:

在此文件缓存中,UrlConnection代码对您没有用处,但剩余的代码可以实现您的目标

在运行时创建图像视图并添加到库中。您的活动应该实现
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;
    }
可视工厂 私有类ImageAdapter扩展了BaseAdapter{ 语境; 私人背景; //私人停车场停车场停车场停车场停车场停车场停车场停车场停车场停车场停车场停车场停车场停车场停车场停车场停车场停车场停车场; 公共图像适配器(上下文c){ mContext=c; //tempBitmap.clear(); //tempBitmap=hashMap.get(“页面”+pageCount); tempbitmap=newArrayList(); tempbitmap.clear(); int end=pageCount*5; int start=end-5; tempbitmap=bitmapArray.subList(开始、结束); TypedArray attr=获得的StyledAttributes(R.styleable.HelloGallery); itemBackground=attr.getResourceId( R.styleable.HelloGallery_android_galleryItemBackground,0); attr.recycle(); //layoutInflater=来自(c)的layoutInflater; } @凌驾 public int getCount(){ //TODO自动生成的方法存根 返回tempbitmap.size(); } @凌驾 公共视图getView(int位置、视图转换视图、视图组arg2){ //TODO自动生成的方法存根 图像视图图像视图; 如果(convertView==null){//如果它没有被回收,初始化一些属性 imageView=新的imageView(mContext); setLayoutParams(新的Gallery.LayoutParams(170,grid_main.getHeight()); imageView.setScaleType(imageView.ScaleType.FIT_XY); imageView.setBackgroundResource(itemBackground); //设置填充(8,8,8,8); }否则{ imageView=(imageView)convertView; } setImageBitmap(tempbitmap.get(position)); 返回图像视图; } @凌驾 公共对象getItem(int位置){ //TODO自动生成的方法存根 返回null; } @凌驾 公共长getItemId(int位置){ //TODO自动生成的方法存根 返回0; } } @凌驾 公共视图makeView(){ //TODO自动生成的方法存根 ImageView ImageView=新的ImageView(此); imageView.setScaleType(imageView.ScaleType.FIT_CENTER); imageView.setLayoutParams(新 ImageSwitcher.LayoutParams( LayoutParams.FILL\u父级, LayoutParams.FILL_PARENT)); imageView.setBackgroundColor(0xFF000000); 返回图像视图; }
这只发生在平板电脑上,其他任何手机都不会发生?是的,这只发生在平板电脑上