2011-12-27 49 views

回答

1

我能够通过使最终位置并添加一个onClick监听到的ImageView来获得点击图像的位置。这记录了被点击的图像的位置。

@Override 
public View getView(final 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(85, 85)); 
    imageView.setScaleType(ImageView.ScaleType.CENTER_CROP); 
    imageView.setPadding(8, 8, 8, 8); 


    imageView.setOnClickListener(new View.OnClickListener() { 

     @Override 
     public void onClick(View view) { 
     Log.d("onClick","position ["+position+"]"); 
     } 

    }); 

    } 
    else { 
    imageView = (ImageView) convertView; 
    } 

    imageView.setImageResource(mThumbIds[position]); 
    return imageView; 
} 


或使用本:
对于一个GridView可以使用setOnItemClickListener方法有一个OnItemClickListener听众。该侦听器会给你,你必须与签名

onItemClick(AdapterView<?> parent, View v, int position, long id) 

你在哪里得到的项目中被点击的网格的位置,并认为是网格的单元格内覆盖的方法。那是你需要的吗?

+0

也分享你的XML ...... @Rizvan – Ankita

1

是的,你可以用GridView做到这一点。

为了实现这种功能,您必须定义自定义适配器为相同。用ImageViewCheckBox定义一个原始布局文件,并在GridView中膨胀相同的文件。

raw_layout.xml:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" android:layout_height="fill_parent"> 
    <ImageView android:id="@+id/thumbImage" android:layout_width="wrap_content" 
     android:layout_height="wrap_content" android:layout_centerInParent="true" /> 
    <CheckBox android:id="@+id/itemCheckBox" android:layout_width="wrap_content" 
     android:layout_height="wrap_content" android:layout_alignParentRight="true" 
     android:layout_alignParentTop="true" /> 
</RelativeLayout> 

这里是具有相同功能的详细示例:Android custom image gallery with checkbox in grid to select multiple

+0

感谢您的宝贵意见,但我不想要相同的,我只想当用户点击特定的图像在网格视图然后选中标记图像显示在图像的中心,因为它是共享图像在我的问题。 –

+0

@SanatPandey不喜欢试试这个例子吗? –

1

做一个GridView和内部使用自定义布局充气像

<RelativeLayout android:layout_width="wrap_content" 
    android:layout_height="wrap_content"> 
    <ImageView android:layout_width="wrap_content" 
     android:layout_height="wrap_content" android:id="@+id/image_view" /> 
    <ImageView android:layout_width="wrap_content" 
     android:layout_height="wrap_content" android:id="@+id/check_image" android:layout_centerInParent="true"/> 
</RelativeLayout> 
相关问题