0

My GridView at the start of activity look like correct

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

but after scrolling down and up items position changes

enter image description here

my last item in first row has a big text, I think this is my issue this is my getView() code

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;
}
Hamid Shatu
  • 9,664
  • 4
  • 30
  • 41

2 Answers2

1

Your grid items should all have a uniform height. Consider setting a min/max number of lines of text to ensure uniform height, and ensure that the ImageView has a consistent size as well. One way would be to use a known, fixed size for the ImageView rather than simply wrap_content.

adamp
  • 28,862
  • 9
  • 81
  • 69
  • tanks for reply i think my issu is in my big textbox when i scroll up all of first items row aligned from bottom in other page that i have uniform items i don't have this problem i shuld cut my textview?Isn't any way for fix this problem without uniformin items? – Mohammad ali Joneidi Dec 01 '12 at 20:32
0

You should change your getView method like this.

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;
}

Your problem is that when you use convertView it stores old data form the first records. Convert view is used to avoid layout inflation from resource which costs you time and memory. You should use the old inflated view, but set new data.

Pratik Butani
  • 60,504
  • 58
  • 273
  • 437
  • I've update my code but it's not working, any help please I need it badly: http://stackoverflow.com/questions/32401630/gridview-images-are-changing-postion-when-scrolling – Monzer Yaghi Sep 04 '15 at 16:05