我正在将图像加载到图库视图中,同时滚动图像,它似乎是一种摇摇欲坠或似乎卡住..我希望有一个平滑的滚动画廊。仅当我在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;
}
答案 0 :(得分:0)
public class 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;
}
通过以下链接查看延迟适配器实现:
https://github.com/thest1/LazyList/tree/master/src/com/fedorvlasov/lazylist
在这个FileCache中,UrlConnection代码对您没用,但剩下的代码可以实现您的目标
答案 1 :(得分: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;
}