旋转时,Android Gridview数据会丢失

时间:2016-04-12 14:23:51

标签: android gridview rotation

我正在开发一款应用。其中,gridview有14个图像。当我将旋转设置为270度和90度图像时,第一个位置只显示10个图像,最后几个图像丢失。

我在这里缺少什么?

非常感谢任何帮助。先谢谢你。

这是xml代码

<GridView
        android:id="@+id/grid_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:numColumns="2"
        android:rotation="270"
        android:stretchMode="columnWidth">

这是适配器类

public class ImageAdapter extends BaseAdapter {
    private Context mContext;

    // Keep all Images in array
    public Integer[] mThumbIds = {
            R.drawable.add, R.drawable.camera_green,
            R.drawable.delete, R.drawable.flag_english,
            R.drawable.flag_dutch, R.drawable.ic_launcher,
            R.drawable.ic_checked, R.drawable.pin_enter,
            R.drawable.ic_relations_g, R.drawable.right_arrow,
            R.drawable.ic_overview_g, R.drawable.gallery,
            R.drawable.close_btn, R.drawable.ic_launcher
    };

    // Constructor
    public ImageAdapter(Context c) {
        mContext = c;
    }

    @Override
    public int getCount() {
        return mThumbIds.length;
    }

    @Override
    public Object getItem(int position) {
        return mThumbIds[position];
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        ImageView imageView = new ImageView(mContext);
        imageView.setImageResource(mThumbIds[position]);
        imageView.setLayoutParams(new GridView.LayoutParams(200, 200));

        imageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Log.v("click item position", "" + position);
            }
        });
        return imageView;
    }

img1

img2

0 个答案:

没有答案