android.view.ViewPropertyAnimator#alpha ( )源码实例Demo

下面列出了android.view.ViewPropertyAnimator#alpha ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

/**
 * Animates the visibility of a tab's close button.
 *
 * @param viewHolder
 *         The view holder, which holds a reference to the close button, whose visibility should
 *         be animated, as an instance of the class {@link AbstractTabViewHolder}. The view
 *         holder may not be null
 * @param show
 *         True, if the close button should be shown, false otherwise
 */
private void animateCloseButtonVisibility(@NonNull final AbstractTabViewHolder viewHolder,
                                          final boolean show) {
    ImageButton closeButton = viewHolder.closeButton;
    Boolean visible = (Boolean) closeButton.getTag(R.id.tag_visibility);

    if (visible == null || visible != show) {
        closeButton.setTag(R.id.tag_visibility, show);

        if (closeButton.getAnimation() != null) {
            closeButton.getAnimation().cancel();
        }

        ViewPropertyAnimator animation = closeButton.animate();
        animation.setListener(createCloseButtonVisibilityAnimationListener(viewHolder, show));
        animation.alpha(show ? 1 : 0);
        animation.setStartDelay(0);
        animation.setDuration(closeButtonVisibilityAnimationDuration);
        animation.start();
    }
}
 
/**
 * Adapts the visibility of the view, which is shown, when the tab switcher is empty.
 *
 * @param animationDuration
 *         The duration of the fade animation, which should be used to show or hide the view, in
 *         milliseconds as a {@link Long} value
 */
private void adaptEmptyView(final long animationDuration) {
    detachEmptyView();

    if (getModel().isEmpty()) {
        emptyView = getModel().getEmptyView();

        if (emptyView != null) {
            emptyView.setAlpha(0);
            FrameLayout.LayoutParams layoutParams =
                    new FrameLayout.LayoutParams(emptyView.getLayoutParams().width,
                            emptyView.getLayoutParams().height);
            layoutParams.gravity = Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL;
            getTabSwitcher().addView(emptyView, 0, layoutParams);
            ViewPropertyAnimator animation = emptyView.animate();
            animation.setDuration(
                    animationDuration == -1 ? emptyViewAnimationDuration : animationDuration);
            animation.alpha(1);
            animation.start();
        }
    }
}
 
/**
 * Creates an animator, which should be used for a fade animation.
 *
 * @param animatedView
 *         The animated view as an instance of the class {@link View}. The view may not be null
 * @param animation
 *         The animation as an instance of the class {@link FadeAnimation}. The animation may
 *         not be null
 * @param listener
 *         The listener, which should be notified about the animation's events, as an instance
 *         of the type {@link AnimatorListener} or null, if no listener should be notified
 * @param show
 *         True, if the animation should be used to show the dialog, false otherwise
 * @return The animator, which has been created, as an instance of the class {@link
 * ViewPropertyAnimator} or null, if no animation should be used
 */
private ViewPropertyAnimator createAnimator(@NonNull final View animatedView,
                                            @NonNull final FadeAnimation animation,
                                            @Nullable final AnimatorListener listener,
                                            final boolean show) {
    if (animation.getAlpha() != null) {
        ViewPropertyAnimator animator =
                animatedView.animate().setInterpolator(animation.getInterpolator())
                        .setDuration(getDuration(animatedView, animation))
                        .setStartDelay(animation.getStartDelay()).setListener(listener);

        if (show) {
            animatedView.setAlpha(animation.getAlpha());
            animator.alpha(1);
        } else {
            animatedView.setAlpha(1f);
            animator.alpha(animation.getAlpha());
        }

        return animator;
    }

    return null;
}
 
源代码4 项目: Genius-Android   文件: BalloonMarker.java
@Override
public void onOpeningComplete() {
    mNumber.setVisibility(View.VISIBLE);

    ViewPropertyAnimator animator = mNumber.animate();
    animator.alpha(1f);
    animator.setDuration(100);
    animator.start();

    /*
    ViewCompat.animate(mNumber)
            .alpha(1f)
            .setDuration(100)
            .start();
    */

    if (getParent() instanceof BalloonMarkerDrawable.MarkerAnimationListener) {
        ((BalloonMarkerDrawable.MarkerAnimationListener) getParent()).onOpeningComplete();
    }
}
 
源代码5 项目: AchievementView   文件: FunctionsUtil.java
public static void applyAlpha(View view, long delay, float alpha, Animator.AnimatorListener animatorListener){
    ViewPropertyAnimator animator2 = view.animate();
    animator2.alpha(alpha);
    animator2.setInterpolator(new DecelerateInterpolator());
    animator2.setStartDelay(delay);
    animator2.setListener(animatorListener);
    animator2.start();
}
 
/**
 * Animates the position, size and alpha of a specific tab in order to swipe it orthogonally.
 *
 * @param item
 *         The item, corresponds to the tab, which should be animated, as an instance of the
 *         class {@link AbstractItem}. The item may not be null
 * @param remove
 *         True, if the tab should be removed after the animation has finished, false otherwise
 * @param delayMultiplier
 *         The multiplied, which should be used to calculate the delay after which the animation
 *         should be started, by being multiplied with the default delay, as an {@link Integer}
 *         value
 * @param swipeAnimation
 *         The animation, which should be used, as an instance of the class {@link
 *         SwipeAnimation}. The animation may not be null
 * @param listener
 *         The listener, which should be notified about the progress of the animation, as an
 *         instance of the type {@link AnimatorListener} or null, if no listener should be
 *         notified
 */
private void animateSwipe(@NonNull final AbstractItem item, final boolean remove,
                          final int delayMultiplier,
                          @NonNull final SwipeAnimation swipeAnimation,
                          @Nullable final AnimatorListener listener) {
    View view = item.getView();
    float currentScale = getArithmetics().getScale(item, true);
    float swipePosition = calculateSwipePosition();
    float targetPosition = remove ?
            (swipeAnimation.getDirection() == SwipeDirection.LEFT_OR_TOP ? -1 * swipePosition :
                    swipePosition) : 0;
    float currentPosition = getArithmetics().getPosition(Axis.ORTHOGONAL_AXIS, item);
    float distance = Math.abs(targetPosition - currentPosition);
    long animationDuration = swipeAnimation.getDuration() != -1 ? swipeAnimation.getDuration() :
            Math.round(swipeAnimationDuration * (distance / swipePosition));
    ViewPropertyAnimator animation = view.animate();
    animation.setInterpolator(
            swipeAnimation.getInterpolator() != null ? swipeAnimation.getInterpolator() :
                    new AccelerateDecelerateInterpolator());
    animation.setListener(new AnimationListenerWrapper(listener));
    animation.setDuration(animationDuration);
    getArithmetics()
            .animatePosition(Axis.ORTHOGONAL_AXIS, animation, item, targetPosition, true);
    getArithmetics().animateScale(Axis.ORTHOGONAL_AXIS, animation,
            remove ? swipedTabScale * currentScale : currentScale);
    getArithmetics().animateScale(Axis.DRAGGING_AXIS, animation,
            remove ? swipedTabScale * currentScale : currentScale);
    animation.alpha(remove ? swipedTabAlpha : 1);
    animation.setStartDelay(delayMultiplier * calculateAnimationDelay(animationDuration));
    animation.start();
}
 
/**
 * Creates and returns an animation listener, which allows to hide a tab, which has been added
 * by using a peek animation, when the animation has been ended.
 *
 * @param item
 *         The item, which corresponds to the tab, which has been added by using the peek
 *         animation, as an instance of the class {@link AbstractItem}. The item may not be
 *         null
 * @param peekAnimation
 *         The peek animation as an instance of the class {@link PeekAnimation}. The peek
 *         animation may not be null
 * @return The listener, which has been created, as an instance of the type {@link
 * AnimatorListener}. The listener may not be null
 */
@NonNull
private AnimatorListener createPeekAnimationListener(@NonNull final AbstractItem item,
                                                     @NonNull final PeekAnimation peekAnimation) {
    return new AnimatorListenerAdapter() {

        @Override
        public void onAnimationEnd(final Animator animation) {
            super.onAnimationEnd(animation);
            long totalDuration =
                    peekAnimation.getDuration() != -1 ? peekAnimation.getDuration() :
                            peekAnimationDuration;
            long duration = totalDuration / 3;
            Interpolator interpolator =
                    peekAnimation.getInterpolator() != null ? peekAnimation.getInterpolator() :
                            new AccelerateDecelerateInterpolator();
            View view = item.getView();
            getArithmetics().setPivot(Axis.DRAGGING_AXIS, item, tabTitleContainerHeight);
            getArithmetics().setPivot(Axis.ORTHOGONAL_AXIS, item,
                    getArithmetics().getSize(Axis.ORTHOGONAL_AXIS, item) / 2f);
            ViewPropertyAnimator animator = view.animate();
            animator.setDuration(duration);
            animator.setStartDelay(duration);
            animator.setInterpolator(interpolator);
            animator.setListener(
                    new AnimationListenerWrapper(createRevertPeekAnimationListener(item)));
            animator.alpha(0);
            getArithmetics().animatePosition(Axis.DRAGGING_AXIS, animator, item,
                    getArithmetics().getPosition(Axis.DRAGGING_AXIS, item) * 1.5f);
            getArithmetics().animateScale(Axis.DRAGGING_AXIS, animator, 0);
            getArithmetics().animateScale(Axis.ORTHOGONAL_AXIS, animator, 0);
            animator.start();
        }

    };
}
 
源代码8 项目: OmegaRecyclerView   文件: DropDownItemAnimator.java
@Override
protected void setupAddAnimation(ViewPropertyAnimator animator, final OmegaExpandableRecyclerView.Adapter.ChildViewHolder holder) {
    animator.setDuration(holder.animationHelper.havePendingRemovals() ? EXPAND_DURATION_LONG : EXPAND_DURATION_SHORT);
    animator.alpha(1f);
    if (holder.animationHelper.upperViewHolder == null) {
        animator.translationY(0f);
    } else {
        animator.setUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
                holder.contentView.setTranslationY(holder.animationHelper.upperViewHolder.contentView.getTranslationY());
            }
        });
    }
}
 
源代码9 项目: ThreePhasesBottomSheet   文件: MyFragment.java
protected void reportState(final BottomSheetState state)
{
if(mBottomSheetState!=state)
  {
  mBottomSheetState=state;
  switch(state)
    {
    case HIDDEN:
      break;
    case HIDDEN_PEEKED:
      break;
    case PEEKED:
      mBottomSheetBackgroundImageView.setImageResource(R.drawable.background);
      mBottomSheetBackgroundImageView.animate().cancel();
      final ViewPropertyAnimator animator=mBottomSheetBackgroundImageView.animate();
      animator.setDuration(getResources().getInteger(android.R.integer.config_shortAnimTime));
      animator.alpha(0);
      break;
    case PEEKED_EXPANDED:
      mBottomSheetBackgroundImageView.animate().cancel();
      mBottomSheetBackgroundImageView.animate().alpha(1);
      break;
    case EXPANDED:
      break;
    }
  }
}
 
源代码10 项目: FlexibleAdapter   文件: EmptyViewHelper.java
private static void showView(View view) {
    if (view != null) {
        ViewPropertyAnimator animator = view.animate();
        animator.cancel();
        animator.alpha(1);
    }
}
 
源代码11 项目: FlexibleAdapter   文件: EmptyViewHelper.java
public static void hideView(View view) {
    if (view != null) {
        ViewPropertyAnimator animator = view.animate();
        animator.cancel();
        animator.alpha(0);
    }
}
 
源代码12 项目: MiBandDecompiled   文件: g.java
public com.nineoldandroids.view.ViewPropertyAnimator alpha(float f)
{
    ViewPropertyAnimator viewpropertyanimator = (ViewPropertyAnimator)b.get();
    if (viewpropertyanimator != null)
    {
        viewpropertyanimator.alpha(f);
    }
    return this;
}
 
源代码13 项目: Genius-Android   文件: BalloonMarker.java
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
public void animateClose() {
    mBalloonMarkerDrawable.stop();

    ViewPropertyAnimator animator = mNumber.animate();
    animator.alpha(0f);
    animator.setDuration(100);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        animator.withEndAction(new Runnable() {
            @Override
            public void run() {
                //We use INVISIBLE instead of GONE to avoid a requestLayout
                mNumber.setVisibility(View.INVISIBLE);
                mBalloonMarkerDrawable.animateToNormal();
            }
        });
    } else {
        animator.setListener(new AnimatorListener() {
            @Override
            public void onAnimationEnd(Animator animation) {
                //We use INVISIBLE instead of GONE to avoid a requestLayout
                mNumber.setVisibility(View.INVISIBLE);
                mBalloonMarkerDrawable.animateToNormal();
            }
        });
    }
    animator.start();
}
 
源代码14 项目: ListBuddies   文件: AboutActivity.java
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
@Override
protected void onPostCreate(Bundle savedInstanceState) {
    super.onPostCreate(savedInstanceState);
    if (Utils.hasHoneycomb()) {
        View demoContainerView = findViewById(R.id.image);
        demoContainerView.setAlpha(0);
        ViewPropertyAnimator animator = demoContainerView.animate();
        animator.alpha(1);
        if (Utils.hasICS()) {
            animator.setStartDelay(250);
        }
        animator.setDuration(1000);
    }
}
 
源代码15 项目: ThreePhasesBottomSheet   文件: MyFragment2.java
protected void reportState(final BottomSheetState state) {
    if (mBottomSheetState == state)
        return;
    mBottomSheetState = state;
    if (state != BottomSheetState.EXPANDED) {
        if (mToolbarAnimation != null) {
            mToolbarAnimation.cancel();
            mToolbarAnimation = null;
        }
        if (mTitleExpandedAnimation != null) {
            mTitleExpandedAnimation.cancel();
            mTitleExpandedAnimation = null;
        }
        mTitleCollapsed.setAlpha(0);
        mTitleExpanded.setAlpha(0);
        mLeftToolbar.setAlpha(0);
        mTitleExpanded.setVisibility(View.INVISIBLE);
        mLeftToolbar.setVisibility(View.INVISIBLE);
    }
    switch (state) {
        case HIDDEN:
            break;
        case HIDDEN_PEEKED:
            break;
        case PEEKED:
            mBottomSheetTopHeader.animate().cancel();
            final ViewPropertyAnimator animator = mBottomSheetTopHeader.animate();
            animator.setDuration(getResources().getInteger(android.R.integer.config_shortAnimTime));
            animator.alpha(0);
            mBottomSheetHeader.setVisibility(View.VISIBLE);
            break;
        case PEEKED_EXPANDED:
            mBottomSheetTopHeader.animate().cancel();
            mBottomSheetTopHeader.animate().alpha(1);
            mBottomSheetHeader.setVisibility(View.GONE);
            break;
        case EXPANDED:
            final float startMarginLeftText = getResources().getDimensionPixelSize(R.dimen.moving_text_expanded_toolbar_margin_left);
            mTitleExpanded.setX(startMarginLeftText);
            mTitleExpanded.setY(mMovingIconImageView.getY() + mMovingImageviewSize * mMovingIconImageView.getScaleY() / 2 - mTitleExpanded.getHeight() / 2);
            mBottomSheetHeader.setVisibility(View.GONE);
            if (mToolbarAnimation == null) {
                mTitleExpanded.setVisibility(View.VISIBLE);
                mLeftToolbar.setVisibility(View.VISIBLE);
                mLeftToolbar.setY(-mLeftToolbar.getHeight() / 3);
                mToolbarAnimation = mLeftToolbar.animate().setDuration(getResources().getInteger(android.R.integer.config_longAnimTime));
                mToolbarAnimation.alpha(1).y(0).start();
                mTitleExpanded.setAlpha(0);
                mTitleExpandedAnimation = mTitleExpanded.animate().setDuration(getResources().getInteger(android.R.integer.config_longAnimTime));
                mTitleExpandedAnimation.alpha(1).start();
            }
            break;
    }
}
 
/**
 * Configures an animator, which should be used to show the dialog using a rectangular reveal
 * animation.
 *
 * @param animatedView
 *         The animated view as an instance of the class {@link View}. The view may not be null
 * @param animation
 *         The animation as an instance of the class {@link RectangleRevealAnimation}. The
 *         animation may not be null
 * @param animator
 *         The animator, which should be configured, as an instance of the class {@link
 *         ViewPropertyAnimator}. The animator may not be null
 */
private void configureShowAnimator(@NonNull final View animatedView,
                                   @NonNull final RectangleRevealAnimation animation,
                                   @NonNull final ViewPropertyAnimator animator) {
    int horizontalWindowInset =
            getDialog().getWindowInsetLeft() + getDialog().getWindowInsetRight();
    int verticalWindowInset =
            getDialog().getWindowInsetTop() + getDialog().getWindowInsetBottom();
    float translationX = 0;
    float translationY = 0;

    if (animation.getX() != null) {
        translationX = animation.getX() - animatedView.getLeft() - horizontalWindowInset;
    }

    if (animation.getY() != null) {
        translationY = animation.getY() - animatedView.getTop() - verticalWindowInset;
    }

    if (animation.getWidth() != null) {
        int viewWidth = animatedView.getWidth() - horizontalWindowInset;
        translationX -= (float) (viewWidth - animation.getWidth()) / 2f;
        animatedView.setScaleX((float) animation.getWidth() / (float) viewWidth);
        animator.scaleX(1);
    }

    if (animation.getHeight() != null) {
        int viewHeight = animatedView.getHeight() - verticalWindowInset;
        translationY -= (float) (viewHeight - animation.getHeight()) / 2f;
        animatedView.setScaleY((float) animation.getHeight() / (float) viewHeight);
        animator.scaleY(1);
    }

    if (animation.getAlpha() != null) {
        animatedView.setAlpha(animation.getAlpha());
        animator.alpha(1);
    }

    if (translationX != 0) {
        animatedView.setTranslationX(translationX);
        animator.translationX(0);
    }

    if (translationY != 0) {
        animatedView.setTranslationY(translationY);
        animator.translationY(0);
    }
}
 
/**
 * Configures an animator, which should be used to hide the dialog using a rectangular reveal
 * animation.
 *
 * @param animatedView
 *         The animated view as an instance of the class {@link View}. The view may not be null
 * @param animation
 *         The animation as an instance of the class {@link RectangleRevealAnimation}. The
 *         animation may not be null
 * @param animator
 *         The animator, which should be configured, as an instance of the class {@link
 *         ViewPropertyAnimator}. The animator may not be null
 */
private void configureHideAnimator(@NonNull final View animatedView,
                                   @NonNull final RectangleRevealAnimation animation,
                                   @NonNull final ViewPropertyAnimator animator) {
    int horizontalWindowInset =
            getDialog().getWindowInsetLeft() + getDialog().getWindowInsetRight();
    int verticalWindowInset =
            getDialog().getWindowInsetTop() + getDialog().getWindowInsetBottom();
    float translationX = 0;
    float translationY = 0;

    if (animation.getX() != null) {
        translationX = animation.getX() - animatedView.getLeft() - horizontalWindowInset;
    }

    if (animation.getY() != null) {
        translationY = animation.getY() - animatedView.getTop() - verticalWindowInset;
    }

    if (animation.getWidth() != null) {
        int viewWidth = animatedView.getWidth() - horizontalWindowInset;
        translationX -= (float) (viewWidth - animation.getWidth()) / 2f;
        animator.scaleX((float) animation.getWidth() / (float) viewWidth);
    }

    if (animation.getHeight() != null) {
        int viewHeight = animatedView.getHeight() - verticalWindowInset;
        translationY -= (float) (viewHeight - animation.getHeight()) / 2f;
        animator.scaleY((float) animation.getHeight() / (float) viewHeight);
    }

    if (animation.getAlpha() != null) {
        animator.alpha(animation.getAlpha());
    }

    if (translationX != 0) {
        animator.translationX(translationX);
    }

    if (translationY != 0) {
        animator.translationY(translationY);
    }
}
 
源代码18 项目: StackOverView   文件: OverviewCardTransform.java
/** Applies this transform to a view. */
public void applyToTaskView(View v, int duration, Interpolator interp, boolean allowLayers,
        boolean allowShadows, ValueAnimator.AnimatorUpdateListener updateCallback) {
    // Check to see if any properties have changed, and update the task view
    if (duration > 0) {
        ViewPropertyAnimator anim = v.animate();
        boolean requiresLayers = false;

        // Animate to the final state
        if (hasTranslationYChangedFrom(v.getTranslationY())) {
            anim.translationY(translationY);
        }
        if (hasScaleChangedFrom(v.getScaleX())) {
            anim.scaleX(scale)
                .scaleY(scale);
            requiresLayers = true;
        }
        if (hasAlphaChangedFrom(v.getAlpha())) {
            // Use layers if we animate alpha
            anim.alpha(alpha);
            requiresLayers = true;
        }
        if (requiresLayers && allowLayers) {
            anim.withLayer();
        }
        anim.setStartDelay(startDelay)
                .setDuration(duration)
                .setInterpolator(interp)
                .start();
    } else {
        // Set the changed properties
        if (hasTranslationYChangedFrom(v.getTranslationY())) {
            v.setTranslationY(translationY);
        }
        if (hasScaleChangedFrom(v.getScaleX())) {
            v.setScaleX(scale);
            v.setScaleY(scale);
        }
        if (hasAlphaChangedFrom(v.getAlpha())) {
            v.setAlpha(alpha);
        }
    }
}
 
源代码19 项目: repay-android   文件: StartFragmentAdapter.java
@Override
public View getView(int position, View convertView, ViewGroup parent) {
    View v = convertView;
    if (v == null) {
        LayoutInflater vi = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        v = vi.inflate(layoutId, null);
    }
    Friend friend = friends.get(position);
    if (friend != null) {
        // TODO Implement View holder pattern
        TextView name = (TextView) v.findViewById(R.id.fragment_start_friendslist_item_name);
        TextView amount = (TextView) v.findViewById(R.id.fragment_start_friendslist_item_amount);
        final RoundedImageView pic = (RoundedImageView) v.findViewById(R.id.fragment_start_friendslist_item_pic);

        v.setTag(friend); // Stored as a tag to be retrieved later for OnItemClickListener

        Log.i(TAG, "Now retrieving contact image");
        ImageLoader.getInstance().displayImage(friend.getLookupURI(), pic, Application.getImageOptions());

        name.setText(friend.getName());

        if (friend.getDebt().compareTo(BigDecimal.ZERO) < 0) {
            pic.setOuterColor(mIOweThemColour);
            amount.setText(SettingsFragment.getCurrencySymbol(mContext) +
                    SettingsFragment.getFormattedAmount(friend.getDebt().negate()));
        } else {
            pic.setOuterColor(mTheyOweMeColour);
            amount.setText(SettingsFragment.getCurrencySymbol(mContext) +
                    SettingsFragment.getFormattedAmount(friend.getDebt()));
        }
    }

    v.setScaleX(0f);
    v.setScaleY(0f);
    v.setAlpha(0f);
    ViewPropertyAnimator animate = v.animate();
    animate.scaleX(1f);
    animate.scaleY(1f);
    animate.alpha(1f);
    animate.setDuration(500);
    animate.start();
    return v;
}