Я пытаюсь поместить три или даже четыре GridView
в один макет и одновременно прокрутить их.
Поскольку GridView
имеет собственный виджет ScrollView
, мне нужно отключить это ScrollView
через свойство android:isScrollContainer="false"
и переопределить GrideView
меру, чтобы иметь функциональность wrap_content
, вот мой расширенный GrideView:
public class ExpandedGridView extends GridView
{
public ExpandedGridView (Context context)
{
super(context);
}
public ExpandedGridView (Context context, AttributeSet attrs)
{
super(context, attrs);
}
public gridView(Context context, AttributeSet attrs, int defStyle)
{
super(context, attrs, defStyle);
}
@Override
public void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
{
// Calculate entire height by providing a very large height hint.
// But do not use the highest 2 bits of this integer; those are
// reserved for the MeasureSpec mode.
int expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE / 2, MeasureSpec.AT_MOST);
super.onMeasure(widthMeasureSpec, expandSpec);
}
}
Работает, но отключает некоторые BaseAdapter
сервиторы, такие как утилизация, повторное использование и т. Д., Так что это делает мой GridView
медленно при прокрутке, и это не достаточно плавно!
Есть идеи, как сделать это быстрее?
Обновление 1: добавлен мой GridAdapter
класс:
public class GridAdapter extends BaseAdapter
{
private Context c;
private DisplayImageOptions mOptions;
private ImageLoader mImageLoader;
private String[] appIconUri, appName, appPrice, appRate;
public GridAdapter(Context c, String[] appIconUri, String[] appName
, String[] appPrice, String[] appRate)
{
this.appIconUri = appIconUri;
this.appName = appName;
this.appPrice = appPrice;
this.appRate = appRate;
this.c = c;
// Setup ImageLoader
this.mImageLoader = ImageLoader.getInstance();
this.mOptions = new DisplayImageOptions.Builder()
.showStubImage(R.drawable.border)
.showImageForEmptyUri(R.drawable.border)
.imageScaleType(ImageScaleType.IN_SAMPLE_INT)
.bitmapConfig(Bitmap.Config.RGB_565)
.resetViewBeforeLoading()
.cacheOnDisc()
.displayer(new FadeInBitmapDisplayer(750))
.build();
if (!mImageLoader.isInited())
{
ImageLoaderConfiguration mImageLoaderConfiguration = new ImageLoaderConfiguration.Builder(c)
.threadPoolSize(2)
.memoryCache(new WeakMemoryCache())
.discCacheFileNameGenerator(new Md5FileNameGenerator())
.build();
mImageLoader.init(mImageLoaderConfiguration);
}
}
public ImageLoader getCurrentImageLoader()
{
return mImageLoader;
}
@Override
public int getCount()
{
return appName.length;
}
@Override
public Object getItem(int itemData)
{
return null;
}
@Override
public long getItemId(int itemPosition)
{
return itemPosition;
}
@Override
public View getView(int position, View convertView, ViewGroup parent)
{
ViewHolder mViewHolder;
if (convertView == null)
{
LayoutInflater mLayoutInflater = ((Activity) c).getLayoutInflater();
convertView = mLayoutInflater.inflate(R.layout.grid_list, null);
mViewHolder = new ViewHolder();
mViewHolder.lblName = (textView) convertView.findViewById(R.id.appName);
mViewHolder.lblPrice = (textView) convertView.findViewById(R.id.appPrice);
mViewHolder.rtbRate = (RatingBar) convertView.findViewById(R.id.appRate);
mViewHolder.imgIcon = (ImageView) convertView.findViewById(R.id.appIcon);
convertView.setTag(mViewHolder);
}
else
mViewHolder = (ViewHolder) convertView.getTag();
mViewHolder.lblName.setText(appName[position]);
// This line should be changed
mViewHolder.lblPrice.setText((Integer.valueOf(appPrice[position]) == 0) ? "مجانی" : appPrice[position]);
mViewHolder.lblPrice.setGravity(Gravity.RIGHT);
mViewHolder.rtbRate.setRating(appRate[position] != null ? Float.valueOf(appRate[position]) : 0);
mImageLoader.displayImage(appIconUri[position], mViewHolder.imgIcon, mOptions);
return convertView;
}
private static class ViewHolder
{
textView lblName, lblPrice;
RatingBar rtbRate;
ImageView imgIcon;
}