如何获取ViewFlipper的当前子视图位置?

32

我已经将许多图片添加到了一个ViewFlipper中,现在我正在执行flipper中的onClick事件。为此,我想知道当前子视图的位置,以便我可以在数组中执行一些操作。有没有办法找出当前子视图的位置。

4个回答

61

使用此方法可获取当前子项的位置:

flipper.getDisplayedChild();

然后将此设置为要查看的子节点编号:

flipper.setDisplayedChild(8);

很高兴听到这个消息。 :) - Awais Tariq

3
addflipperimages(ViewFlipper flipper)方法中,您正在向ViewFlipper添加一堆图像,为此您正在创建imageView,将标签设置为imageView,将imageView clickable设置为true,然后编写imageView的onclick方法。请查看以下代码,它可能适用于您。 这里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);

                  }

}

1
我使用了这个flipper.indexOfChild(flipper.getCurrentView())

1

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接