Android 如何获取ViewFlipper';当前的子位置
我已经向ViewFlipper添加了一组图像,现在我正在flipper中执行onClick事件。为此,我想知道当前子对象的位置,以便在数组中执行一些操作。是否还有其他方法可以找到当前子对象的位置 使用indexOfChild() 查看此帖子Android 如何获取ViewFlipper';当前的子位置,android,Android,我已经向ViewFlipper添加了一组图像,现在我正在flipper中执行onClick事件。为此,我想知道当前子对象的位置,以便在数组中执行一些操作。是否还有其他方法可以找到当前子对象的位置 使用indexOfChild() 查看此帖子 希望这对您有用。使用此选项获取当前子位置: flipper.getDisplayedChild(); 此选项用于设置要查看的子编号: flipper.setDisplayedChild(8); 在addflipperimages(ViewFlipper
希望这对您有用。使用此选项获取当前子位置:
flipper.getDisplayedChild();
此选项用于设置要查看的子编号:
flipper.setDisplayedChild(8);
在addflipperimages(ViewFlipper-flipper)
方法中,您正在为正在创建的imageview向ViewFlipper添加一组图像,将标记设置为imageview,将imageview clickable设置为true,然后将onclick方法写入imageview。浏览休闲代码,它可能对您有效这里的
ids[]
是一个图像id数组
private void addFlipperImages(ViewFlipper flipper) {
int imageCount = ids.length;
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.FILL_PARENT,
RelativeLayout.LayoutParams.FILL_PARENT);
for (int count = 0; count <imageCount; count++) {
ImageView imageView = new ImageView(this);
Bitmap imbm = BitmapFactory.decodeResource(this.getResources(),ids[count]);
imageView.setImageBitmap(imbm);
imageView.setLayoutParams(params);
imageView.setTag(count);
imageView.setClickable(true);
imageView.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
int id=(Integer) v.getTag();
Toast.makeText(ImageSliderVertical.this, id+"", Toast.LENGTH_LONG).show();
}
});
flipper.addView(imageView);
flipper.setTag(count);
}
}
private void addFlipperImage(ViewFlipper-flipper){
int imageCount=ids.length;
RelativeLayout.LayoutParams params=新的RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.FILL\u父级,
RelativeLayout.LayoutParams.FILL\u PARENT);
对于(int count=0;count我使用了这个flipper.indexOfChild(flipper.getCurrentView())
听上去不错。:)