在gridview中滚动的问题(特别是在三星手机中)

时间:2016-04-02 09:27:38

标签: android android-gridview

enter image description here

您好,我在Gridview中遇到问题。并且主要是在三星手机中。有时候图标在滚动时是不可见的,或者在屏幕上留下大量空间。这一切都发生在滚动菜单时。请检查截图。 gridviewadapter.java

public class GridviewAdapter extends ArrayAdapter<HomepageGeSe>
{
    Context context;
    int layoutResourceId;
    ArrayList<HomepageGeSe> data = null;
    RecordHolder holder = null;

    public GridviewAdapter(Context context, int layoutResourceId, ArrayList<HomepageGeSe> data) {
        super(context, layoutResourceId, data);
        this.layoutResourceId = layoutResourceId;
        this.context = context;
        this.data = data;
    }
    static class RecordHolder {
        TextView txtTitle;
        ImageView imageItem;
    }
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        if (convertView == null) {
            LayoutInflater mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            convertView = mInflater.inflate(layoutResourceId, parent, false);
            holder = new RecordHolder();

            holder.txtTitle = (TextView) convertView.findViewById(R.id.item_text);
            holder.imageItem = (ImageView) convertView.findViewById(R.id.item_image);
            convertView.setTag(holder);
        } else {
            holder = (RecordHolder) convertView.getTag();
        }


        HomepageGeSe list = data.get(position);
        holder.txtTitle.setText(list.getName());

        if(list.getDrawableId() != 0)
        {
            holder.txtTitle.setText(list.getName());
            Picasso.with(context)
                    .load(list.getDrawableId())
                    .fit ()
                    .error(R.drawable.imagenotavailable)
                    .into(holder.imageItem);
        }

        return convertView;
    }
}

Homepage.xml

        <?xml version="1.0" encoding="utf-8"?>
        <RelativeLayout
            xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fitsSystemWindows="true"
            android:id = "@+id/rootLayout"
            android:orientation="vertical">
            <ListView
                android:id="@+id/list"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:dividerHeight="1dp"/>
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:fitsSystemWindows="true"
                android:orientation="vertical">
            <GridView
                android:id="@+id/gridView1"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_margin="10dp"
                android:columnWidth="90dp"
                android:gravity="center"
                android:numColumns="auto_fit"
                android:horizontalSpacing="10dp"
                android:verticalSpacing="15dp"
                android:stretchMode="columnWidth" />
        </LinearLayout>
        </RelativeLayout>

    gridview_row.xml

        <?xml version="1.0" encoding="utf-8"?>
        <RelativeLayout
                xmlns:android="http://schemas.android.com/apk/res/android"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:padding="5dp">
            <ImageView
                android:id="@+id/item_image"
                android:layout_width="52dp"
                android:layout_height="52dp"
                android:layout_alignParentTop="true"
                android:layout_centerHorizontal="true"
                android:contentDescription="@string/imageDes">
            </ImageView>
            <TextView
                android:id="@+id/item_text"
                android:layout_below="@+id/item_image"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="2dp"
                android:gravity="center"
                android:textAppearance="?android:attr/textAppearance"
                android:textColor="@color/textview_all">
            </TextView>
            </RelativeLayout>

0 个答案:

没有答案