在我的应用程序中,我有一个Viewflipper,其中将以编程方式从阵列加载四个图像。 但只有最后的鳍状肢图像,我需要显示一个转到按钮。
<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"/>
在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]);
}
对于setflipperImage()方法:
private void setFlipperImage(int res) {
ImageView image = new ImageView(getApplicationContext());
image.setBackgroundResource(res);
mViewFlipper.addView(image);
}
所以请帮助我看看/显示only last flipper image(4th image)
答案 0 :(得分:3)
使用此选项获取当前的Child位置:
flipper.getDisplayedChild();
这是设置要查看的子编号:
flipper.setDisplayedChild(4);
将动画侦听器添加到您设置为viewflipper&#39; IN&#39;的动画对象中。动画。覆盖侦听器onAnimationEnd方法,并在该方法内部检查
if(flipper.getDisplayedChild() == 4)
visible your GO Button
else
hide your button
答案 1 :(得分:2)
在您通过mViewFlipper.setInAnimation
将动画设置为ViewFlipper之前,请向其添加侦听器并覆盖其onAnimationEnd
回调。在那里,您检查ViewFlipper上当前显示的视图,并使按钮可见,如果它是最后一个。
// 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);