简体   繁体   中英

How do I change the View's visibility based on another View's animation in a custom layout?

I created a custom RelativeLayout called WheelLayout which contains two ImageViews. The first View, WheelView, is a custom View that calls RotateAnimation a couple times.

WheelView has a custom interface called WheelListener.

 public interface WheelListener {
    public void wheelStarted();
    public void wheelStoppedOnSlice(int sliceNum);
 } 

In WheelView, I implement Animation.AnimationListener as follows:

@Override
public void onAnimationStart(Animation animation) {
    mListener.wheelStarted();
}

@Override
public void onAnimationEnd(Animation animation) {
        mListener.wheelStoppedOnSlice(mCurrentSlice);
}

@Override
public void onAnimationRepeat(Animation animation) {
}

Where mListener is a WheelListener.

WheelLayout implements WheelListener like so:

@Override
public void wheelStarted() {
   mSliceImage.setVisibility(View.GONE);
}

@Override
public void wheelStoppedOnSlice(int sliceNum) {
    mSliceImage.setBackgroundResource(mSlices[sliceNum]);
    mSliceImage.setVisibility(View.VISIBLE);
}

When WheelView animates, I expect to see mSliceImage disappear and WheelView to continue its animation to completion. Instead, neither occurs. My WheelView does not animate and mSliceImage does not disappear.

However, after the animation would finish, I do see mSliceImage change its background resource.

I also tried the same thing where mSliceImage was not a child of custom layout and it worked perfectly.

Does anyone have any ideas?

problem is you use "View.GONE". you should use "View.INVISIBLE"

try this

 @Override
  public void wheelStarted() {
     mSliceImage.setVisibility(View.INVISIBLE);
  }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM