In my app i have one Viewflipper in which four images will be loaded from array in programmatically. But only for the Last flipper image i need to display a go button.

<ViewFlipper
    android:id="@+id/view_flipper"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >
</ViewFlipper>

<Button
    android:id="@+id/gotoapp"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="go"
    android:visibility="gone"/>

In java:

int gallery_grid_Images[]={R.drawable.splash1,R.drawable.splash2,R.drawable.splash3,R.drawable.splash4};
mViewFlipper = (ViewFlipper) this.findViewById(R.id.view_flipper);
for(int i=0;i<gallery_grid_Images.length;i++)
    {
        setFlipperImage(gallery_grid_Images[i]);
    }

For setflipperImage() method:

     private void setFlipperImage(int res) {
       ImageView image = new ImageView(getApplicationContext());
       image.setBackgroundResource(res);
       mViewFlipper.addView(image);
     }

So please help me how to visible/show the "Go" button for only last flipper image(4th image)

有帮助吗?

解决方案

Use this to get the current Child position:

flipper.getDisplayedChild();

And this to set child number to view:

flipper.setDisplayedChild(4);

Add an animation listener to the animation object you set as the viewflipper's 'IN' animation. Overide the listeners onAnimationEnd method, and inside that method check

 if(flipper.getDisplayedChild() == 4)
      visible your GO Button
     else 
      hide your button

其他提示

Before you set an Animation to your ViewFlipper by mViewFlipper.setInAnimation, add the listener to it and override its onAnimationEnd callback. There, you check which view is currently displaying on your ViewFlipper and make the button visible, if it is the last one.

// load an animation for mViewFlipper, res/anim folder must contain it
mFlipperAnimIn = AnimationUtils.loadAnimation(this, R.anim.view_flipper_in);

// set up the listener
mFlipperAnimIn.setAnimationListener(new AnimationListener() {
    @Override
    public void onAnimationEnd(Animation arg0) {
        // here, if you reach last image, change visibility of your button
        if (mViewFlipper.getDisplayedChild() == mViewFlipper.getChildCount() - 1) {
            buttonGoToApp.setVisibility(View.VISIBLE);
        } else {
            buttonGoToApp.setVisibility(View.GONE);
        }
    }

    // leave other callbacks blank unless you want some other actions caused by animation
    @Override
    public void onAnimationRepeat(Animation arg0) { }

    @Override
    public void onAnimationStart(Animation arg0) { }
});

// finally, set up IN animation for your ViewFlipper
mViewFlipper.setInAnimation(mFlipperAnimIn);
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top