有没有办法设置图库视图,以便一次只能查看一个图像?我创建了一个带有图像缩略图的图库视图。当用户点击图像时,我想开始一个新活动,在新的图库视图中显示实际选定的图像。现在,当用户滑动他的手指时,他可以看到后续图像。有没有办法实现这个目标?
答案 0 :(得分:0)
您可以在图库视图中使用“自定义适配器”作为图库视图,并在 getView(int position,View convertView,ViewGroup)中使用自定义适配器中图像视图的“LayoutParams”使用“match_parent”或“fill_parent”父母)方法。
public View getView(int position, View convertView, ViewGroup parent) {
imageView.setLayoutParams(...);
return imageView;
}
答案 1 :(得分:0)
我遇到了同样的问题而且我做了一个有点工作的黑客。在我的情况下,图像是静态的,所以我使用批量重命名将图像编号为0-100。使用相应的缩略图执行相同的操作。我创建了两个活动一个使用gridview(你可以使用galleryview)来握住拇指和另一个用galleryview我为gridview设置onclicklistener来获取被点击的拇指的id并将其传递给具有galleryview作为额外意图的活动。抓取id并跳转到具有给定id的图像。检查此
答案 2 :(得分:0)
在网上搜索时找到了另一种解决方案。更简单的解决方案是继承Gallery类,只需将onFling设置为始终返回false。以下是解决方案的参考:
How can I limit fling in Android gallery to just one item per fling?
以下是基于上述链接中列出的“Someone Somewhere”和“vmihalca”用户输入的组合实现:
public class SlowGallery extends Gallery {
public SlowGallery(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
public SlowGallery(Context context, AttributeSet attrs) {
super(context, attrs);
}
public SlowGallery(Context context) {
super(context);
}
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
return false;
}
}