简体   繁体   English

如何在图像库中获取焦点的图像(其位置)?

[英]How to get which image (its position) is on focus in an Image Gallery?

I am playing around with the Gallery widget. 我正在玩Gallery小部件。

I would like to know how can we get the position of the image on focus in the gallery. 我想知道如何在图库中获得焦点图像的位置。

For example having several pictures in my gallery, if I tap my finger to the right, pictures will come and go until it stop to one. 例如,在我的画廊中有几张照片,如果我将手指向右滑动,照片将会一直走到一直到一个。

How one can get the position of this one picture that is currently on focus ? 如何才能获得目前关注的这张照片的位置?

I don't know if I was clear enough, if there is anything you want me to add do not hesitate. 我不知道我是否足够清楚,如果有什么要你加我不要犹豫。 Thank you, 谢谢,

Set an OnItemSelectedListener on the Gallery Widget, override appropriate method [I think the callback is named onItemSelected(...) ]. 在Gallery Widget上设置OnItemSelectedListener ,覆盖适当的方法[我认为回调名为onItemSelected(...) ]。 The position of item in focus would be passed as argument to this callback function. 焦点项的位置将作为参数传递给此回调函数。

Pseudo code: 伪代码:

Gallery g = (Gallery) findViewById(R.id.gallery);
//set Adapter with appropriate data model
g.setOnItemSelectedListener(this);

public void onItemSelected(AdapterView parent, View v, int position, long id) {
//position is item having focus
}

Hope that helps... 希望有帮助......

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM