可能重复:
how can I show selection of an image in grid view at once如何显示在网格视图中选择图像的android系统
我有我想要一个复选标记图像的问题表明,当我们选择一个图像从图像中间的网格视图中,意思是假设当我们点击一个网格项时,选中标记图像将出现在图像的中间,显示图像的选择。
对于以下实例都出现在iPhone屏幕:
可能重复:
how can I show selection of an image in grid view at once如何显示在网格视图中选择图像的android系统
我有我想要一个复选标记图像的问题表明,当我们选择一个图像从图像中间的网格视图中,意思是假设当我们点击一个网格项时,选中标记图像将出现在图像的中间,显示图像的选择。
对于以下实例都出现在iPhone屏幕:
我能够通过使最终位置并添加一个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)
你在哪里得到的项目中被点击的网格的位置,并认为是网格的单元格内覆盖的方法。那是你需要的吗?
是的,你可以用GridView
做到这一点。
为了实现这种功能,您必须定义自定义适配器为相同。用ImageView
和CheckBox
定义一个原始布局文件,并在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
。
感谢您的宝贵意见,但我不想要相同的,我只想当用户点击特定的图像在网格视图然后选中标记图像显示在图像的中心,因为它是共享图像在我的问题。 –
@SanatPandey不喜欢试试这个例子吗? –
做一个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>
也分享你的XML ...... @Rizvan – Ankita