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

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

/**
 * Determines if the supplied {@link View} is visible to the user, which requires that it be
 * marked visible, that all its parents are visible, that it and all parents have alpha greater
 * than 0, and that it has non-zero size. This code attempts to replicate the protected method
 * {@code View.isVisibleToUser}.
 *
 * @param view The {@link View} to evaluate
 * @return {@code true} if {@code view} is visible to the user
 */
@RequiresApi(Build.VERSION_CODES.HONEYCOMB) // Uses View#getAlpha
public static boolean isVisibleToUser(View view) {
  if (view == null) {
    return false;
  }

  Object current = view;
  while (current instanceof View) {
    View currentView = (View) current;
    if ((currentView.getAlpha() <= 0) || (currentView.getVisibility() != View.VISIBLE)) {
      return false;
    }
    current = currentView.getParent();
  }
  return view.getGlobalVisibleRect(new Rect());
}
 
源代码2 项目: sa-sdk-android   文件: ViewUtil.java
/**
 * View 自身是否可见
 *
 * @return View 宽、高、透明度 有一个 < 0 时,或 getLocalVisibleRect 为 false 时;返回 false 。
 * View getVisibility 不可见,且有 Animation getFillAfter 为  false 时;返回 false 。
 * View 无 Animation 时 getVisibility 不可见时返回 false 。
 */
@RequiresApi(api = 11)
public static boolean isViewSelfVisible(View view) {
    if (view == null) {
        return false;
    }
    if (view.getWidth() <= 0 || view.getHeight() <= 0 || view.getAlpha() <= 0.0f || !view.getLocalVisibleRect(new Rect())) {
        return false;
    }
    return (view.getVisibility() != VISIBLE && view.getAnimation() != null && view.getAnimation().getFillAfter()) || view.getVisibility() == VISIBLE;
}
 
源代码3 项目: scene   文件: AnimatorUtility.java
@NonNull
public static AnimatorInfo captureViewStatus(@NonNull View view) {
    return new AnimatorInfo(view.getTranslationX(),
            view.getTranslationY(),
            view.getScaleX(),
            view.getScaleY(),
            view.getRotation(),
            view.getRotationX(),
            view.getRotationY(),
            view.getAlpha());
}
 
源代码4 项目: DevUtils   文件: ViewUtils.java
/**
 * 获取 View 透明度
 * @param view View
 * @return 透明度
 */
public static float getAlpha(final View view) {
    if (view != null) {
        return view.getAlpha();
    }
    return 1.0f;
}
 
源代码5 项目: Mover   文件: ViewPropertyAnimatorHC.java
/**
 * This method gets the value of the named property from the View object.
 *
 * @param propertyConstant The property whose value should be returned
 * @return float The value of the named property
 */
private float getValue(int propertyConstant) {
    //final View.TransformationInfo info = mView.mTransformationInfo;
    View v = mView.get();
    if (v != null) {
        switch (propertyConstant) {
            case TRANSLATION_X:
                //return info.mTranslationX;
                return v.getTranslationX();
            case TRANSLATION_Y:
                //return info.mTranslationY;
                return v.getTranslationY();
            case ROTATION:
                //return info.mRotation;
                return v.getRotation();
            case ROTATION_X:
                //return info.mRotationX;
                return v.getRotationX();
            case ROTATION_Y:
                //return info.mRotationY;
                return v.getRotationY();
            case SCALE_X:
                //return info.mScaleX;
                return v.getScaleX();
            case SCALE_Y:
                //return info.mScaleY;
                return v.getScaleY();
            case X:
                //return v.mLeft + info.mTranslationX;
                return v.getX();
            case Y:
                //return v.mTop + info.mTranslationY;
                return v.getY();
            case ALPHA:
                //return info.mAlpha;
                return v.getAlpha();
        }
    }
    return 0;
}
 
源代码6 项目: Material-In   文件: MaterialIn.java
public static void startAnimators(final View view, int startOffsetX, int startOffsetY, long delay) {
    if (view.getVisibility() == View.VISIBLE && view.getAlpha() != 0f) {
        view.clearAnimation();
        view.animate().cancel();
        final Resources res = view.getResources();
        final float endAlpha = view.getAlpha();
        final float endTranslateX = view.getTranslationX();
        final float endTranslateY = view.getTranslationY();
        view.setAlpha(0);
        final Animator fade = ObjectAnimator.ofFloat(view, View.ALPHA, endAlpha);
        fade.setDuration(res.getInteger(R.integer.material_in_fade_anim_duration));
        fade.setInterpolator(new AccelerateInterpolator());
        fade.setStartDelay(delay);
        fade.start();
        ViewPropertyAnimator slide = view.animate();
        if (startOffsetY != 0) {
            view.setTranslationY(startOffsetY);
            slide.translationY(endTranslateY);
        } else {
            view.setTranslationX(startOffsetX);
            slide.translationX(endTranslateX);
        }
        slide.setInterpolator(new DecelerateInterpolator(2));
        slide.setDuration(res.getInteger(R.integer.material_in_slide_anim_duration));
        slide.setStartDelay(delay);
        slide.setListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationCancel(Animator animation) {
                if (fade.isStarted()) {
                    fade.cancel();
                }
                view.setAlpha(endAlpha);
                view.setTranslationX(endTranslateX);
                view.setTranslationY(endTranslateY);
            }
        });
        slide.start();
    }
}
 
源代码7 项目: UltimateAndroid   文件: ViewPropertyAnimatorHC.java
/**
 * This method gets the value of the named property from the View object.
 *
 * @param propertyConstant The property whose value should be returned
 * @return float The value of the named property
 */
private float getValue(int propertyConstant) {
    //final View.TransformationInfo info = mView.mTransformationInfo;
    View v = mView.get();
    if (v != null) {
        switch (propertyConstant) {
            case TRANSLATION_X:
                //return info.mTranslationX;
                return v.getTranslationX();
            case TRANSLATION_Y:
                //return info.mTranslationY;
                return v.getTranslationY();
            case ROTATION:
                //return info.mRotation;
                return v.getRotation();
            case ROTATION_X:
                //return info.mRotationX;
                return v.getRotationX();
            case ROTATION_Y:
                //return info.mRotationY;
                return v.getRotationY();
            case SCALE_X:
                //return info.mScaleX;
                return v.getScaleX();
            case SCALE_Y:
                //return info.mScaleY;
                return v.getScaleY();
            case X:
                //return v.mLeft + info.mTranslationX;
                return v.getX();
            case Y:
                //return v.mTop + info.mTranslationY;
                return v.getY();
            case ALPHA:
                //return info.mAlpha;
                return v.getAlpha();
        }
    }
    return 0;
}
 
源代码8 项目: okhttp-OkGo   文件: SimpleViewBehavior.java
/** 初始化数据 */
private void prepare(CoordinatorLayout parent, View child, View dependency) {
    mDependStartX = (int) dependency.getX();
    mDependStartY = (int) dependency.getY();
    mDependStartWidth = dependency.getWidth();
    mDependStartHeight = dependency.getHeight();
    mStartX = (int) child.getX();
    mStartY = (int) child.getY();
    mStartWidth = child.getWidth();
    mStartHeight = child.getHeight();
    mStartAlpha = child.getAlpha();
    mStartRotateX = child.getRotationX();
    mStartRotateY = child.getRotationY();

    //特殊处理y方向变化
    if (mDependTargetY == UNSPECIFIED_INT && dependency instanceof AppBarLayout) {
        mDependTargetY = ((AppBarLayout) dependency).getTotalScrollRange();
    }
    // 背景颜色渐变
    if (child.getBackground() instanceof ColorDrawable) mStartBackgroundColor = ((ColorDrawable) child.getBackground()).getColor();
    // 自定义动画
    if (mAnimationId != 0) {
        mAnimation = AnimationUtils.loadAnimation(child.getContext(), mAnimationId);
        mAnimation.initialize(child.getWidth(), child.getHeight(), parent.getWidth(), parent.getHeight());
    }
    // 兼容5.0以上的沉浸模式
    if (Build.VERSION.SDK_INT > 16 && parent.getFitsSystemWindows() && targetY != UNSPECIFIED_INT) {
        targetY += getStatusBarHeight(parent.getContext());
    }
    isPrepared = true;
}
 
源代码9 项目: floatingMenu   文件: SubButton.java
public SubButton(View view, int width, int height) {
    this.view = view;
    this.width = width;
    this.height = height;
    this.alpha = view.getAlpha();
    this.x = 0;
    this.y = 0;
}
 
源代码10 项目: LB-Launcher   文件: DragController.java
/**
 * Draw the view into a bitmap.
 */
Bitmap getViewBitmap(View v) {
    v.clearFocus();
    v.setPressed(false);

    boolean willNotCache = v.willNotCacheDrawing();
    v.setWillNotCacheDrawing(false);

    // Reset the drawing cache background color to fully transparent
    // for the duration of this operation
    int color = v.getDrawingCacheBackgroundColor();
    v.setDrawingCacheBackgroundColor(0);
    float alpha = v.getAlpha();
    v.setAlpha(1.0f);

    if (color != 0) {
        v.destroyDrawingCache();
    }
    v.buildDrawingCache();
    Bitmap cacheBitmap = v.getDrawingCache();
    if (cacheBitmap == null) {
        Log.e(TAG, "failed getViewBitmap(" + v + ")", new RuntimeException());
        return null;
    }

    Bitmap bitmap = Bitmap.createBitmap(cacheBitmap);

    // Restore the view
    v.destroyDrawingCache();
    v.setAlpha(alpha);
    v.setWillNotCacheDrawing(willNotCache);
    v.setDrawingCacheBackgroundColor(color);

    return bitmap;
}
 
源代码11 项目: Auie   文件: UEViewHelper.java
static float getAlpha(View view) {
    return view.getAlpha();
}
 
源代码12 项目: CircularReveal   文件: DynamicAnimation.java
@Override
public float getValue(View view) {
  return view.getAlpha();
}
 
源代码13 项目: android-test   文件: ViewMatchers.java
@Override
public boolean matchesSafely(View view) {
  return view.getAlpha() == alpha;
}
 
源代码14 项目: imsdk-android   文件: ViewHelper.java
static float getAlpha(View view) {
    return view.getAlpha();
}
 
源代码15 项目: weex   文件: ViewUtil.java
@Override
public float getAlpha(View view) {
  return view.getAlpha();
}
 
源代码16 项目: guideshow   文件: ViewCompatHC.java
public static float getAlpha(View view) {
    return view.getAlpha();
}
 
源代码17 项目: litho   文件: MountState.java
private static void unsetAlpha(View view, NodeInfo nodeInfo) {
  if (nodeInfo.isAlphaSet() && view.getAlpha() != 1) {
    view.setAlpha(1);
  }
}
 
源代码18 项目: UltimateAndroid   文件: ViewHelper.java
static float getAlpha(View view) {
    return view.getAlpha();
}
 
源代码19 项目: Telegram-FOSS   文件: MediaActivity.java
private void updateSections(RecyclerView listView, boolean checkTopBottom) {
    int count = listView.getChildCount();
    int minPositionDateHolder = Integer.MAX_VALUE;
    View minDateChild = null;
    float padding = listView.getPaddingTop() + actionBar.getTranslationY();
    int minTop = Integer.MAX_VALUE;
    int maxBottom = 0;

    for (int a = 0; a < count; a++) {
        View view = listView.getChildAt(a);
        int bottom = view.getBottom();
        minTop = Math.min(minTop, view.getTop());
        maxBottom = Math.max(bottom, maxBottom);
        if (bottom <= padding) {
            continue;
        }
        int position = view.getBottom();
        if (view instanceof SharedMediaSectionCell || view instanceof GraySectionCell) {
            if (view.getAlpha() != 1.0f) {
                view.setAlpha(1.0f);
            }
            if (position < minPositionDateHolder) {
                minPositionDateHolder = position;
                minDateChild = view;
            }
        }
    }
    if (minDateChild != null) {
        if (minDateChild.getTop() > padding) {
            if (minDateChild.getAlpha() != 1.0f) {
                minDateChild.setAlpha(1.0f);
            }
        } else {
            if (minDateChild.getAlpha() != 0.0f) {
                minDateChild.setAlpha(0.0f);
            }
        }
    }
    if (checkTopBottom) {
        if (maxBottom != 0 && maxBottom < (listView.getMeasuredHeight() - listView.getPaddingBottom())) {
            resetScroll();
        } else if (minTop != Integer.MAX_VALUE && minTop > listView.getPaddingTop() + actionBar.getTranslationY()) {
            scrollWithoutActionBar(listView, -listView.computeVerticalScrollOffset());
            resetScroll();
        }
    }
}
 
源代码20 项目: Transitions-Everywhere   文件: ViewUtils.java
public float getTransitionAlpha(@NonNull View v) {
    return v.getAlpha();
}
 
 方法所在类
 同类方法