gpt4 book ai didi

android - 同时滚动三个 GridView

转载 作者:行者123 更新时间:2023-11-30 04:16:20 26 4
gpt4 key购买 nike

我试图将三个甚至四个 GridView 放在一个布局中并同时滚动它们。

由于 GridView 有自己的 ScrollView 小部件,我需要通过 android:isScrollContainer="false"禁用那个 ScrollView 属性并覆盖 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;
}

最佳答案

快速搜索后,我找到了一个已经有人创建的库 http://tonicartos.github.io/StickyGridHeaders/无需重新发明轮子。

关于android - 同时滚动三个 GridView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9927978/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com