android.view.View#setAlpha ( )源码实例Demo

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

public static void openH(final RecyclerView.ViewHolder holder, final View expandView, final boolean animate, int heightAnimateTime, final ViewHolderAnimator.AnimatorListener animatorListener) {
    if (animate) {
        expandView.setVisibility(View.VISIBLE);
        final Animator animator = ViewHolderAnimator.ofItemViewHeight(holder, heightAnimateTime);
        animator.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                if(animatorListener != null) {
                    animatorListener.onAnimatorEnd();
                }
                final ObjectAnimator alphaAnimator = ObjectAnimator.ofFloat(expandView, View.ALPHA, 1);
                alphaAnimator.addListener(new ViewHolderAnimator.ViewHolderAnimatorListener(holder));
                alphaAnimator.start();
            }
        });
        animator.start();
    }
    else {
        expandView.setVisibility(View.VISIBLE);
        expandView.setAlpha(1);
    }
}
 
源代码2 项目: PowerFileExplorer   文件: ABaseTransformer.java
/**
 * Called each {@link #transformPage(android.view.View, float)} before {{@link #onTransform(android.view.View, float)}.
 * <p>
 * The default implementation attempts to reset all view properties. This is useful when toggling transforms that do
 * not modify the same page properties. For instance changing from a transformation that applies rotation to a
 * transformation that fades can inadvertently leave a fragment stuck with a rotation or with some degree of applied
 * alpha.
 * 
 * @param page
 *            Apply the transformation to this page
 * @param position
 *            Position of page relative to the current front-and-center position of the pager. 0 is front and
 *            center. 1 is one full page position to the right, and -1 is one page position to the left.
 */
protected void onPreTransform(View page, float position) {
	final float width = page.getWidth();

	page.setRotationX(0);
	page.setRotationY(0);
	page.setRotation(0);
	page.setScaleX(1);
	page.setScaleY(1);
	page.setPivotX(0);
	page.setPivotY(0);
	page.setTranslationY(0);
	page.setTranslationX(isPagingEnabled() ? 0f : -width * position);

	if (hideOffscreenPages()) {
		page.setAlpha(position <= -1f || position >= 1f ? 0f : 1f);
		page.setEnabled(false);
	} else {
		page.setEnabled(true);
		page.setAlpha(1f);
	}
}
 
源代码3 项目: AndroidProject   文件: PickerLayoutManager.java
/**
 * 横向情况下的缩放
 */
private void scaleHorizontalChildView() {
    float mid = getWidth() / 2.0f;
    for (int i = 0; i < getChildCount(); i++) {
        View childView =  getChildAt(i);
        if (childView != null) {
            float childMid = (getDecoratedLeft(childView) + getDecoratedRight(childView)) / 2.0f;
            float scale = 1.0f + (-1 * (1 - mScale)) * (Math.min(mid, Math.abs(mid - childMid))) / mid;
            childView.setScaleX(scale);
            childView.setScaleY(scale);
            if (mAlpha) {
                childView.setAlpha(scale);
            }
        }
    }
}
 
源代码4 项目: o2oa   文件: StickyListAdapter.java
@Override
public View getHeaderView(int position, View convertView, ViewGroup parent) {
    HeaderViewHolder holder;
    FriendEntry model = mData.get(position);
    if (convertView == null) {
        holder = new HeaderViewHolder();
        convertView = mInflater.inflate(R.layout.header, parent, false);
        if (Build.VERSION.SDK_INT >= 11) {
            convertView.setAlpha(0.85f);
        }
        holder.text = (TextView) convertView.findViewById(R.id.section_tv);
        convertView.setTag(holder);
    } else {
        holder = (HeaderViewHolder) convertView.getTag();
    }

    //根据position获取分类的首字母的Char ascii值
    int section = getSectionForPosition(position);
    holder.text.setText(model.letter);
    //如果当前位置等于该分类首字母的Char的位置 ,则认为是第一次出现
    if (position == getPositionForSection(section)) {
        holder.text.setText(model.letter);
    }
    return convertView;
}
 
源代码5 项目: MoeQuest   文件: DepthTransFormes.java
public void transformPage(View view, float position) {

    int pageWidth = view.getWidth();

    if (position < -1) { // [-Infinity,-1)
      // This page is way off-screen to the left.
      view.setAlpha(0);
    } else if (position <= 0) { // [-1,0]
      // Use the default slide transition when moving to the left page
      view.setAlpha(1);
      view.setTranslationX(0);
      view.setScaleX(1);
      view.setScaleY(1);
    } else if (position <= 1) { // (0,1]
      // Fade the page out.
      view.setAlpha(1 - position);

      // Counteract the default slide transition
      view.setTranslationX(pageWidth * -position);

      // Scale the page down (between MIN_SCALE and 1)
      float scaleFactor = MIN_SCALE
          + (1 - MIN_SCALE) * (1 - Math.abs(position));
      view.setScaleX(scaleFactor);
      view.setScaleY(scaleFactor);
    } else { // (1,+Infinity]
      // This page is way off-screen to the right.
      view.setAlpha(0);
    }
  }
 
private static void updateReplyIconTransition(@NonNull View replyIcon, float dx, float progress, float sign) {
  if (progress > 0.05f) {
    replyIcon.setAlpha(REPLY_ALPHA_INTERPOLATOR.getInterpolation(progress));
  } else replyIcon.setAlpha(0f);

  replyIcon.setTranslationX(REPLY_TRANSITION_INTERPOLATOR.getInterpolation(progress) * sign);

  if (dx < TRIGGER_DX) {
    float scale = REPLY_SCALE_INTERPOLATOR.getInterpolation(progress);
    replyIcon.setScaleX(scale);
    replyIcon.setScaleY(scale);
  }
}
 
源代码7 项目: ReadMark   文件: MultiFloatingActionButton.java
private void scaleToShow(){
    for(int i = 2; i<getChildCount(); i++){
        View view = getChildAt(i);
        view.setVisibility(VISIBLE);
        view.setAlpha(0);
        ObjectAnimator scaleX = ObjectAnimator.ofFloat(view, "scaleX", 0f, 1f);
        ObjectAnimator scaleY = ObjectAnimator.ofFloat(view, "scaleY", 0f, 1f);
        ObjectAnimator alpha = ObjectAnimator.ofFloat(view, "alpha", 0f, 1f);
        AnimatorSet set = new AnimatorSet();
        set.playTogether(scaleX, scaleY, alpha);
        set.setDuration(mAnimationDuration);
        set.start();
    }
}
 
源代码8 项目: android-md-core   文件: AlphaAnimator.java
@Override
public void onAnimationUpdate(ValueAnimator animation) {
  View target = mTarget.get();
  if (target != null) {
    float alpha = (float) animation.getAnimatedValue();
    target.setAlpha(alpha);
  }
}
 
源代码9 项目: mvvm-template   文件: AnimHelper.java
@UiThread public static void mimicFabVisibility(boolean show, @NonNull View view,
                                                @Nullable FloatingActionButton.OnVisibilityChangedListener listener) {
    if (show) {
        view.animate().cancel();
        if (ViewCompat.isLaidOut(view)) {
            if (view.getVisibility() != View.VISIBLE) {
                view.setAlpha(0f);
                view.setScaleY(0f);
                view.setScaleX(0f);
            }
            view.animate()
                    .scaleX(1f)
                    .scaleY(1f)
                    .alpha(1f)
                    .setDuration(200)
                    .setInterpolator(LINEAR_OUT_SLOW_IN_INTERPOLATOR)
                    .withStartAction(() -> {
                        view.setVisibility(View.VISIBLE);
                        if (listener != null) listener.onShown(null);
                    });
        } else {
            view.setVisibility(View.VISIBLE);
            view.setAlpha(1f);
            view.setScaleY(1f);
            view.setScaleX(1f);
            if (listener != null) listener.onShown(null);
        }
    } else {
        view.animate()
                .scaleX(0f)
                .scaleY(0f)
                .alpha(0f)
                .setDuration(40)
                .setInterpolator(FAST_OUT_LINEAR_IN_INTERPOLATOR);
        view.setVisibility(View.GONE);
        if (listener != null) listener.onHidden(null);
    }
}
 
源代码10 项目: hr   文件: SliderHelper.java
public void transformPage(View view, float position) {
    int pageWidth = view.getWidth();
    int pageHeight = view.getHeight();

    if (position < -1) { // [-Infinity,-1)
        // This page is way off-screen to the left.
        view.setAlpha(0);

    } else if (position <= 1) { // [-1,1]
        // Modify the default slide transition to shrink the page as well
        float scaleFactor = Math.max(MIN_SCALE, 1 - Math.abs(position));
        float vertMargin = pageHeight * (1 - scaleFactor) / 2;
        float horzMargin = pageWidth * (1 - scaleFactor) / 2;
        if (position < 0) {
            view.setTranslationX(horzMargin - vertMargin / 2);
        } else {
            view.setTranslationX(-horzMargin + vertMargin / 2);
        }

        // Scale the page down (between MIN_SCALE and 1)
        view.setScaleX(scaleFactor);
        view.setScaleY(scaleFactor);

        // Fade the page relative to its size.
        view.setAlpha(MIN_ALPHA +
                (scaleFactor - MIN_SCALE) /
                        (1 - MIN_SCALE) * (1 - MIN_ALPHA));

    } else { // (1,+Infinity]
        // This page is way off-screen to the right.
        view.setAlpha(0);
    }
}
 
private void setAlpha(View view, float alpha, long durationMillis) {
    if (Build.VERSION.SDK_INT < 11) {
        final AlphaAnimation animation = new AlphaAnimation(alpha, alpha);
        animation.setDuration(durationMillis);
        animation.setFillAfter(true);
        view.startAnimation(animation);
    } else {
        view.setAlpha(alpha);
    }
}
 
源代码12 项目: Banner   文件: FlipVerticalTransformer.java
@Override
protected void onTransform(View view, float position) {
    final float rotation = -180f * position;

    view.setAlpha(rotation > 90f || rotation < -90f ? 0f : 1f);
    view.setPivotX(view.getWidth() * 0.5f);
    view.setPivotY(view.getHeight() * 0.5f);
    view.setRotationX(rotation);
}
 
@Override
public void transformPage(View page, float position) {

    page.setTranslationX(-position * page.getWidth());
    page.setCameraDistance(12000);

    if (position < 0.5 && position > -0.5) {
        page.setVisibility(View.VISIBLE);
    } else {
        page.setVisibility(View.INVISIBLE);
    }



    if (position < -1){     // [-Infinity,-1)
        // This page is way off-screen to the left.
        page.setAlpha(0);

    }
    else if (position <= 0) {    // [-1,0]
        page.setAlpha(1);
        page.setRotationY(900 *(1-Math.abs(position)+1));

    }
    else if (position <= 1) {    // (0,1]
        page.setAlpha(1);
        page.setRotationY(-900 *(1-Math.abs(position)+1));

    }
    else {    // (1,+Infinity]
        // This page is way off-screen to the right.
        page.setAlpha(0);

    }


}
 
源代码14 项目: Trebuchet   文件: Overview.java
@Override
public void screenScrolled(View v, float progress) {
    float scale =1.0f - 0.1f * mScaleInterpolator
            .getInterpolation(Math.min(0.3f, Math.abs(progress)) / 0.3f);

    v.setPivotX(progress < 0 ? 0 : v.getMeasuredWidth());
    v.setPivotY(v.getMeasuredHeight() * 0.5f);
    v.setScaleX(scale);
    v.setScaleY(scale);
    v.setAlpha(scale);
}
 
源代码15 项目: NanoIconPack   文件: SimplePageTransformer.java
private void transformPageZoomOut(View view, float position) {
    final float MIN_SCALE = 0.85f;
    final float MIN_ALPHA = 0.5f;

    int pageWidth = view.getWidth();
    int pageHeight = view.getHeight();

    if (position < -1) { // [-Infinity,-1)
        // This page is way off-screen to the left.
        view.setAlpha(0);
    } else if (position <= 1) { // [-1,1]
        // Modify the default slide transition to shrink the page as well
        float scaleFactor = Math.max(MIN_SCALE, 1 - Math.abs(position));
        float verMargin = pageHeight * (1 - scaleFactor) / 2;
        float horzMargin = pageWidth * (1 - scaleFactor) / 2;
        if (position < 0) {
            view.setTranslationX(horzMargin - verMargin / 2);
        } else {
            view.setTranslationX(-horzMargin + verMargin / 2);
        }

        // Scale the page down (between MIN_SCALE and 1)
        view.setScaleX(scaleFactor);
        view.setScaleY(scaleFactor);

        // Fade the page relative to its size.
        view.setAlpha(MIN_ALPHA + (scaleFactor - MIN_SCALE) / (1 - MIN_SCALE) * (1 - MIN_ALPHA));
    } else { // (1,+Infinity]
        // This page is way off-screen to the right.
        view.setAlpha(0);
    }
}
 
源代码16 项目: weex-uikit   文件: TransformItemDecoration.java
private void updateItem(View child, int width, int height) {
  int size,childCenter,containerSize;
  if (mIsVertical) {
    containerSize = height;
    size = child.getHeight();
    childCenter = child.getTop() + size / 2;
  } else {
    containerSize = width;
    size = child.getWidth();
    childCenter = child.getLeft() + size / 2;
  }

  final int actionDistance = (containerSize + size) / 2;
  final float effectsAmount = Math.min(1.0f, Math.max(-1.0f, (1.0f / actionDistance) * (childCenter - containerSize/2)));


  if(mAlpha>0){
    child.setAlpha(1-mAlpha*Math.abs(effectsAmount));
  }

  if(mScaleX>0||mScaleY>0){
    child.setScaleX(1-mScaleX*Math.abs(effectsAmount));
    child.setScaleY(1-mScaleY*Math.abs(effectsAmount));
  }

  if(mRotation!=0){
    child.setRotation(mRotation * effectsAmount);
  }

  if(mXTranslate!=0){
    child.setTranslationX(mXTranslate * Math.abs( effectsAmount));
  }

  if(mYTranslate!=0){
    child.setTranslationY(mYTranslate * Math.abs( effectsAmount));
  }

}
 
源代码17 项目: VideoOS-Android-SDK   文件: UDView.java
/**
 * 设置view的alpha
 */
public UDView setAlpha(float alpha) {
    View view = getView();
    if (view != null) {
        view.setAlpha(alpha);
    }
    return this;
}
 
源代码18 项目: WIFIADB   文件: AlphaProperty.java
@Override
public void set(View object, Float value) {
    object.setAlpha(value);
}
 
源代码19 项目: adt-leanback-support   文件: ViewCompatHC.java
public static void setAlpha(View view, float value) {
    view.setAlpha(value);
}
 
源代码20 项目: android-ConstraintLayoutExamples   文件: FadeOut.java
@Override
public void setProgress(View view, float progress) {
    view.setAlpha(1f - progress);
}
 
 方法所在类
 同类方法