1

我在android中编码图像gridview,我想问你如何在用户单击gridview中的小图像时显示大图像以及如何使gridview能够通过滑动滚动,因为我的画廊有很多图像。

这是我的代码:

public class myalbum extends Activity {

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.myalbum);

    GridView gridView = (GridView) findViewById(R.id.gridview);
    gridView.setAdapter(new ImageAdapter(this));

    gridView.setOnItemClickListener(new GridView.OnItemClickListener() 
    {
        public void onItemClick(AdapterView<?> parent, View v, int position, long id) 
        {                
            //Here I want to see Large Image???? How can i do?????
            Toast.makeText(myalbum.this, "" + position, Toast.LENGTH_SHORT).show();
        }
    });        
}

public class ImageAdapter extends BaseAdapter {
    private Context mContext;

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

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

    public Object getItem(int position) {
        return null;
    }

    public long getItemId(int position) {
        return 0;
    }

    HashMap<Integer, Matrix> mImageTransforms = new HashMap<Integer,Matrix>();
    Matrix mIdentityMatrix = new Matrix();
    //---returns an ImageView view---
 // create a new ImageView for each item referenced by the Adapter
    public View getView(int position, View convertView, ViewGroup parent) {
        ImageView imageView;
        if (convertView == null) {  // if it's not recycled, initialize some attributes
            imageView = new ImageView(mContext);
            imageView.setLayoutParams(new GridView.LayoutParams(88, 88));
            imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
            imageView.setPadding(2, 2, 2, 2);
        } else {
            imageView = (ImageView) convertView;
        }

        Matrix m = mImageTransforms.get(position);
        if ( null == m ) {
            m = mIdentityMatrix;
        }
        imageView.setImageMatrix(m);
        imageView.setImageResource(mThumbIds[position]);
        return imageView;
    }

    void setImageRotation(int position, int degrees) {
        Matrix m = mImageTransforms.remove(position);        
        if ( degrees != 0 ) {
            if ( null == m ) m = new Matrix();
            m.setRotate(degrees);
            mImageTransforms.put(position, m);
        }
        notifyDataSetChanged();
    }

    private Integer[] mThumbIds = {
            R.drawable.p1, R.drawable.p2,
            R.drawable.p1, R.drawable.p2,
            R.drawable.p1, R.drawable.p2,
            R.drawable.p1, R.drawable.p2,
            R.drawable.p3, R.drawable.p4
    };
  }
}

最好的问候, 维拉克

4

1 回答 1

1

实际上,我无法到达您实际想要显示图像的位置。顺便说一句,您需要在 FrameLayout 中添加您的网格视图,之后您可以以编程方式创建布局(背景颜色透明)以相同的方式将 imageView 添加到它并将该布局添加到您的 frameLayout 并在图像上单击您可以设置它可见性为可见,因此它在您的网格视图顶部显示图像,因为您只需在 FB 上查看图像并提供关闭按钮,该按钮将该布局的可见性设置为 Gone。

希望这对您有所帮助。让我知道是否有任何问题..

于 2012-05-18T15:14:02.777 回答