我試圖在一個佈局中放入三個或甚至四個GridView
並同時滾動它們。同時滾動三個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;
}
你可以顯示你同時滾動的網格截圖嗎?..我的意思是,如何在屏幕上對齊? – bakriOnFire 2013-05-10 14:18:32
對我來說,你似乎很奇怪,你需要同時在屏幕上顯示多個GridView,你可能首先想重新考慮這個設計。你能提供一個你試圖效仿的例子嗎?你也不解釋你爲什麼要包裝內容的工作,否則你可以嘗試同步滾動列表。 – Eluvatar 2013-05-10 14:23:07
@bakriOnFire請參閱此鏈接澄清http://www.jayway.com/2012/10/04/how-to-make-the-height-of-a-gridview-wrap-its-content/ – iSun 2013-05-10 14:40:44