我正在玩画廊小部件。
我想知道我们如何才能让图像在画廊中的焦点位置。
例如,在我的图库中有几张图片,如果我用手指向右轻按,图片就会来来去去,直到停止到一张为止。
如何获得当前焦点所在的这张图片的位置?
我不知道我是否足够清楚,如果您有什么要我补充的,请不要犹豫。谢谢,
在 Gallery Widget 上设置一个OnItemSelectedListener
,覆盖适当的方法 [我认为回调名为onItemSelected(...)
]。焦点中项目的位置将作为参数传递给此回调函数。
伪代码:
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
}
希望有帮助...