0

GridView在活动开始时看起来是正确的

http://i.stack.imgur.com/p41lb.jpg

但是在向下和向上滚动项目位置更改后

在此处输入图像描述

我第一行的最后一项有一个大文本,我认为这是我的问题这是我的getView()代码

public View getView(int position, View convertView, ViewGroup parent) {
    View v;
    if (convertView == null) {
        LayoutInflater li = getLayoutInflater();
        v= li.inflate(R.layout.item, null);
    } else {
    v= convertView;
    }
    ImageView imageView = (ImageView) v.findViewById(R.id.grid_item_image);
    imageView.setImageResource(R.drawable.logo);
    TextView textView = (TextView) v.findViewById(R.id.grid_item_label);
    textView.setText(PersianReshape.reshape( Values[position].getName()));
    Typeface face = Typeface.createFromAsset(context.getAssets(),"font/BNazanin.ttf");
    textView.setTypeface(face);
    textView.setTextSize(farin.code.rahnamee.attrib.attribute.content_font_size);
    return gridView;
}
4

2 回答 2

1

您的网格项目都应该具有统一的高度。考虑设置最小/最大文本行数以确保统一的高度,并确保也ImageView具有一致的大小。一种方法是使用已知的固定大小ImageView而不是简单的wrap_content.

于 2012-12-01T20:03:41.777 回答
0

您应该像这样更改您的 getView 方法。

public View getView(int position, View convertView, ViewGroup parent){
    // TODO Auto-generated method stub
    View v;
    if(convertView==null)
    {
        LayoutInflater li = getLayoutInflater();
        v = li.inflate(R.layout.icontext, null);
    }else{
        v = convertView;
    }
    TextView tv = (TextView)v.findViewById(R.id.icon_text);
    tv.setText(providers[position]);
    ImageView iv = (ImageView)v.findViewById(R.id.icon_image);
    iv.setImageResource(R.drawable.icon);

    return v;
}

您的问题是,当您使用 convertView 时,它会从第一条记录中存储旧数据。转换视图用于避免资源的布局膨胀,这会花费您的时间和内存。您应该使用旧的膨胀视图,但设置新数据。

于 2013-03-02T04:46:12.433 回答