本文整理汇总了Java中android.support.v4.view.ViewCompat.getAlpha方法的典型用法代码示例。如果您正苦于以下问题:Java ViewCompat.getAlpha方法的具体用法?Java ViewCompat.getAlpha怎么用?Java ViewCompat.getAlpha使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.support.v4.view.ViewCompat
的用法示例。
在下文中一共展示了ViewCompat.getAlpha方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onUpdateViewAlpha
import android.support.v4.view.ViewCompat; //导入方法依赖的package包/类
@Override
protected void onUpdateViewAlpha(@NonNull View view, float alpha) {
final CardView card = ((CardView)view);
final View alphaView = card.getChildAt(1);
final View imageView = card.getChildAt(0);
final boolean isLeftCard = alpha < 1;
if (isLeftCard) {
ViewCompat.setAlpha(alphaView, 0.9f - alpha);
ViewCompat.setAlpha(imageView, 0.3f + alpha);
} else {
if (ViewCompat.getAlpha(alphaView) != 0) {
ViewCompat.setAlpha(alphaView, 0f);
}
if (ViewCompat.getAlpha(imageView) != 1) {
ViewCompat.setAlpha(imageView, 1f);
}
}
}
示例2: animateChange
import android.support.v4.view.ViewCompat; //导入方法依赖的package包/类
@Override
public boolean animateChange(ViewHolder oldHolder, ViewHolder newHolder, int fromX, int fromY,
int toX, int toY) {
final float prevTranslationX = ViewCompat.getTranslationX(oldHolder.itemView);
final float prevTranslationY = ViewCompat.getTranslationY(oldHolder.itemView);
final float prevAlpha = ViewCompat.getAlpha(oldHolder.itemView);
endAnimation(oldHolder);
int deltaX = (int) (toX - fromX - prevTranslationX);
int deltaY = (int) (toY - fromY - prevTranslationY);
// recover prev translation state after ending animation
ViewCompat.setTranslationX(oldHolder.itemView, prevTranslationX);
ViewCompat.setTranslationY(oldHolder.itemView, prevTranslationY);
ViewCompat.setAlpha(oldHolder.itemView, prevAlpha);
if (newHolder != null && newHolder.itemView != null) {
// carry over translation values
endAnimation(newHolder);
ViewCompat.setTranslationX(newHolder.itemView, -deltaX);
ViewCompat.setTranslationY(newHolder.itemView, -deltaY);
ViewCompat.setAlpha(newHolder.itemView, 0);
}
mPendingChanges.add(new ChangeInfo(oldHolder, newHolder, fromX, fromY, toX, toY));
return true;
}
示例3: setImageDrawable
import android.support.v4.view.ViewCompat; //导入方法依赖的package包/类
/**
* change the image with a fade
*
* @param drawable
* @param fadeDuration
*/
public static void setImageDrawable(final ImageView imageView, final Drawable drawable, final int fadeDuration) {
final float alpha = ViewCompat.getAlpha(imageView);
final ImageView viewToAnimate = imageView;
fadeOut(viewToAnimate, fadeDuration, new ViewPropertyAnimatorListenerAdapter() {
@Override
public void onAnimationEnd(View view) {
super.onAnimationEnd(view);
//change the image when alpha=0
imageView.setImageDrawable(drawable);
//then fade to alpha=1
fadeIn(viewToAnimate, alpha, fadeDuration, new ViewPropertyAnimatorListenerAdapter());
}
});
}
示例4: animateChange
import android.support.v4.view.ViewCompat; //导入方法依赖的package包/类
public boolean animateChange(ViewHolder oldHolder, ViewHolder newHolder, int fromX, int fromY, int toX, int toY) {
if (oldHolder == newHolder) {
return animateMove(oldHolder, fromX, fromY, toX, toY);
}
float prevTranslationX = ViewCompat.getTranslationX(oldHolder.itemView);
float prevTranslationY = ViewCompat.getTranslationY(oldHolder.itemView);
float prevAlpha = ViewCompat.getAlpha(oldHolder.itemView);
resetAnimation(oldHolder);
int deltaX = (int) (((float) (toX - fromX)) - prevTranslationX);
int deltaY = (int) (((float) (toY - fromY)) - prevTranslationY);
ViewCompat.setTranslationX(oldHolder.itemView, prevTranslationX);
ViewCompat.setTranslationY(oldHolder.itemView, prevTranslationY);
ViewCompat.setAlpha(oldHolder.itemView, prevAlpha);
if (newHolder != null) {
resetAnimation(newHolder);
ViewCompat.setTranslationX(newHolder.itemView, (float) (-deltaX));
ViewCompat.setTranslationY(newHolder.itemView, (float) (-deltaY));
ViewCompat.setAlpha(newHolder.itemView, 0.0f);
}
this.mPendingChanges.add(new ChangeInfo(oldHolder, newHolder, fromX, fromY, toX, toY));
return true;
}
示例5: intersectVisibleToUser
import android.support.v4.view.ViewCompat; //导入方法依赖的package包/类
private boolean intersectVisibleToUser(Rect localRect) {
if (localRect == null || localRect.isEmpty() || this.mView.getWindowVisibility() != 0) {
return false;
}
ViewParent viewParent = this.mView.getParent();
while (viewParent instanceof View) {
View view = (View) viewParent;
if (ViewCompat.getAlpha(view) <= 0.0f || view.getVisibility() != 0) {
return false;
}
viewParent = view.getParent();
}
if (viewParent == null || !this.mView.getLocalVisibleRect(this.mTempVisibleRect)) {
return false;
}
return localRect.intersect(this.mTempVisibleRect);
}
示例6: animateChange
import android.support.v4.view.ViewCompat; //导入方法依赖的package包/类
@Override
public boolean animateChange(ViewHolder oldHolder, ViewHolder newHolder,
int fromX, int fromY, int toX, int toY) {
if (oldHolder == newHolder) {
// Don't know how to run change animations when the same view holder is re-used.
// run a move animation to handle position changes.
return animateMove(oldHolder, fromX, fromY, toX, toY);
}
final float prevTranslationX = ViewCompat.getTranslationX(oldHolder.itemView);
final float prevTranslationY = ViewCompat.getTranslationY(oldHolder.itemView);
final float prevAlpha = ViewCompat.getAlpha(oldHolder.itemView);
resetAnimation(oldHolder);
int deltaX = (int) (toX - fromX - prevTranslationX);
int deltaY = (int) (toY - fromY - prevTranslationY);
// Recover prev translation state after ending animation
ViewCompat.setTranslationX(oldHolder.itemView, prevTranslationX);
ViewCompat.setTranslationY(oldHolder.itemView, prevTranslationY);
ViewCompat.setAlpha(oldHolder.itemView, prevAlpha);
if (newHolder != null) {
// Carry over translation values
resetAnimation(newHolder);
ViewCompat.setTranslationX(newHolder.itemView, -deltaX);
ViewCompat.setTranslationY(newHolder.itemView, -deltaY);
ViewCompat.setAlpha(newHolder.itemView, 0);
}
mPendingChanges.add(new ChangeInfo(oldHolder, newHolder, fromX, fromY, toX, toY));
return true;
}
示例7: showCheckedView
import android.support.v4.view.ViewCompat; //导入方法依赖的package包/类
private void showCheckedView(boolean show)
{
float alpha = show ? 1.0f : 0f;
if (ViewCompat.getAlpha(mViewChecked) != alpha)
{
ViewCompat.setAlpha(mViewChecked, alpha);
}
}
示例8: animateChange
import android.support.v4.view.ViewCompat; //导入方法依赖的package包/类
@Override
public boolean animateChange(ViewHolder oldHolder, ViewHolder newHolder,
int fromX, int fromY, int toX, int toY) {
if (oldHolder == newHolder) {
// Don't know how to run change animations when the same view holder is re-used.
// run a move animation to handle position changes.
return animateMove(oldHolder, fromX, fromY, toX, toY);
}
final float prevTranslationX = ViewCompat.getTranslationX(oldHolder.itemView);
final float prevTranslationY = ViewCompat.getTranslationY(oldHolder.itemView);
final float prevAlpha = ViewCompat.getAlpha(oldHolder.itemView);
resetAnimation(oldHolder);
int deltaX = (int) (toX - fromX - prevTranslationX);
int deltaY = (int) (toY - fromY - prevTranslationY);
// recover prev translation state after ending animation
ViewCompat.setTranslationX(oldHolder.itemView, prevTranslationX);
ViewCompat.setTranslationY(oldHolder.itemView, prevTranslationY);
ViewCompat.setAlpha(oldHolder.itemView, prevAlpha);
if (newHolder != null) {
// carry over translation values
resetAnimation(newHolder);
ViewCompat.setTranslationX(newHolder.itemView, -deltaX);
ViewCompat.setTranslationY(newHolder.itemView, -deltaY);
ViewCompat.setAlpha(newHolder.itemView, 0);
}
mPendingChanges.add(new ChangeInfo(oldHolder, newHolder, fromX, fromY, toX, toY));
return true;
}
示例9: animateChange
import android.support.v4.view.ViewCompat; //导入方法依赖的package包/类
@Override
public boolean animateChange(RecyclerView.ViewHolder oldHolder, RecyclerView.ViewHolder newHolder,
int fromX, int fromY, int toX, int toY) {
if (oldHolder == newHolder) {
// Don't know how to run change animations when the same view holder is re-used.
// run a move animation to handle position changes.
return animateMove(oldHolder, fromX, fromY, toX, toY);
}
final float prevTranslationX = ViewCompat.getTranslationX(oldHolder.itemView);
final float prevTranslationY = ViewCompat.getTranslationY(oldHolder.itemView);
final float prevAlpha = ViewCompat.getAlpha(oldHolder.itemView);
resetAnimation(oldHolder);
int deltaX = (int) (toX - fromX - prevTranslationX);
int deltaY = (int) (toY - fromY - prevTranslationY);
// recover prev translation state after ending animation
ViewCompat.setTranslationX(oldHolder.itemView, prevTranslationX);
ViewCompat.setTranslationY(oldHolder.itemView, prevTranslationY);
ViewCompat.setAlpha(oldHolder.itemView, prevAlpha);
if (newHolder != null) {
// carry over translation values
resetAnimation(newHolder);
ViewCompat.setTranslationX(newHolder.itemView, -deltaX);
ViewCompat.setTranslationY(newHolder.itemView, -deltaY);
ViewCompat.setAlpha(newHolder.itemView, 0);
}
mPendingChanges.add(new ChangeInfo(oldHolder, newHolder, fromX, fromY, toX, toY));
return true;
}
示例10: onDraw
import android.support.v4.view.ViewCompat; //导入方法依赖的package包/类
@Override
public void onDraw(Canvas canvas, RecyclerView parent, RecyclerView.State state) {
int visibleCount = parent.getChildCount();
int count = state.getItemCount();
RecyclerView.Adapter adapter = parent.getAdapter();
int adapterCount = adapter != null ? adapter.getItemCount() : 0;
for (int i = 0; i < visibleCount; i++) {
View view = parent.getChildAt(i);
int position = parent.getChildAdapterPosition(view);
float translationX = ViewCompat.getTranslationX(view);
float translationY = ViewCompat.getTranslationY(view);
float alpha = ViewCompat.getAlpha(view);
RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) view.getLayoutParams();
int shadows = LEFT|RIGHT;
if(position == count - 1 && adapterCount != 0) shadows|=BOTTOM;
drawable.setAlpha((int) (255*alpha));
drawable.setShadow(shadows);
drawable.setBounds(0, 0, parent.getWidth(), view.getHeight());
int saved = canvas.save();
canvas.translate(parent.getPaddingLeft() + translationX,
view.getTop() + params.topMargin + translationY);
drawable.draw(canvas);
canvas.restoreToCount(saved);
}
}
示例11: updateView
import android.support.v4.view.ViewCompat; //导入方法依赖的package包/类
@Override
public void updateView(@NonNull View view, float position) {
super.updateView(view, position);
final CardView card = ((CardView)view);
final View alphaView = card.getChildAt(1);
final View imageView = card.getChildAt(0);
if (position < 0) {
final float alpha = ViewCompat.getAlpha(view);
ViewCompat.setAlpha(view, 1f);
ViewCompat.setAlpha(alphaView, 0.9f - alpha);
ViewCompat.setAlpha(imageView, 0.3f + alpha);
} else {
ViewCompat.setAlpha(alphaView, 0f);
ViewCompat.setAlpha(imageView, 1f);
}
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
final CardSliderLayoutManager lm = getLayoutManager();
final float ratio = (float) lm.getDecoratedLeft(view) / lm.getActiveCardLeft();
final float z;
if (position < 0) {
z = Z_CENTER_1 * ratio;
} else if (position < 0.5f) {
z = Z_CENTER_1;
} else if (position < 1f) {
z = Z_CENTER_2;
} else {
z = Z_RIGHT;
}
card.setCardElevation(Math.max(0, z));
}
}
示例12: onDrawOver
import android.support.v4.view.ViewCompat; //导入方法依赖的package包/类
@Override
public void onDrawOver(Canvas c, RecyclerView parent, RecyclerView.State state) {
int lastChildPosition = -1;
int childCount = mShowLastDivider ? parent.getChildCount() : parent.getChildCount() - 1;
for (int i = 0; i < childCount; i++) {
View child = parent.getChildAt(i);
int childPosition = parent.getChildAdapterPosition(child);
if (childPosition < lastChildPosition) {
// Avoid remaining divider when animation starts
continue;
}
lastChildPosition = childPosition;
if (ViewCompat.getAlpha(child) < 1) {
// Avoid remaining divider when animation starts
continue;
}
if (mVisibilityProvider.shouldHideDivider(childPosition, parent)) {
continue;
}
Rect bounds = getDividerBound(childPosition, parent, child);
switch (mDividerType) {
case DRAWABLE:
Drawable drawable = mDrawableProvider.drawableProvider(childPosition, parent);
drawable.setBounds(bounds);
drawable.draw(c);
break;
case PAINT:
mPaint = mPaintProvider.dividerPaint(childPosition, parent);
c.drawLine(bounds.left, bounds.top, bounds.right, bounds.bottom, mPaint);
break;
case COLOR:
mPaint.setColor(mColorProvider.dividerColor(childPosition, parent));
mPaint.setStrokeWidth(mSizeProvider.dividerSize(childPosition, parent));
c.drawLine(bounds.left, bounds.top, bounds.right, bounds.bottom, mPaint);
break;
}
}
}
示例13: onDraw
import android.support.v4.view.ViewCompat; //导入方法依赖的package包/类
@Override
public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) {
int lastChildPosition = -1;
int childCount = mShowLastDivider ? parent.getChildCount() : parent.getChildCount() - 1;
for (int i = 0; i < childCount; i++) {
View child = parent.getChildAt(i);
int childPosition = parent.getChildAdapterPosition(child);
if (childPosition < lastChildPosition) {
// Avoid remaining divider when animation starts
continue;
}
lastChildPosition = childPosition;
if (ViewCompat.getAlpha(child) < 1) {
// Avoid remaining divider when animation starts
continue;
}
if (mVisibilityProvider.shouldHideDivider(childPosition, parent)) {
continue;
}
Rect bounds = getDividerBound(childPosition, parent, child);
switch (mDividerType) {
case DRAWABLE:
Drawable drawable = mDrawableProvider.drawableProvider(childPosition, parent);
drawable.setBounds(bounds);
drawable.draw(c);
break;
case PAINT:
mPaint = mPaintProvider.dividerPaint(childPosition, parent);
c.drawLine(bounds.left, bounds.top, bounds.right, bounds.bottom, mPaint);
break;
case COLOR:
mPaint.setColor(mColorProvider.dividerColor(childPosition, parent));
mPaint.setStrokeWidth(mSizeProvider.dividerSize(childPosition, parent));
c.drawLine(bounds.left, bounds.top, bounds.right, bounds.bottom, mPaint);
break;
}
}
}
示例14: animateChange
import android.support.v4.view.ViewCompat; //导入方法依赖的package包/类
@Override
public boolean animateChange(ViewHolder oldHolder, ViewHolder newHolder,
int fromX, int fromY, int toX, int toY) {
// if (oldHolder != newHolder) {
// if (oldHolder != null) {
// dispatchChangeFinished(oldHolder, true);
// }
// if (newHolder != null) {
// dispatchChangeFinished(newHolder, false);
// }
// } else if (oldHolder != null) {
// dispatchChangeFinished(oldHolder, true);
// }
// return false;
if (oldHolder == newHolder) {
// Don't know how to run change animations when the same view holder is re-used.
// run a move animation to handle position changes.
if ((fromX - toX) == 0 && (fromY - toY) == 0) {
dispatchMoveFinished(oldHolder);
return false;
}
return animateMove(oldHolder, fromX, fromY, toX, toY);
}
final float prevTranslationX = ViewCompat.getTranslationX(oldHolder.itemView);
final float prevTranslationY = ViewCompat.getTranslationY(oldHolder.itemView);
final float prevAlpha = ViewCompat.getAlpha(oldHolder.itemView);
resetAnimation(oldHolder);
int deltaX = (int) (toX - fromX - prevTranslationX);
int deltaY = (int) (toY - fromY - prevTranslationY);
// recover prev translation state after ending animation
ViewCompat.setTranslationX(oldHolder.itemView, prevTranslationX);
ViewCompat.setTranslationY(oldHolder.itemView, prevTranslationY);
ViewCompat.setAlpha(oldHolder.itemView, prevAlpha);
if (newHolder != null) {
// carry over translation values
resetAnimation(newHolder);
ViewCompat.setTranslationX(newHolder.itemView, -deltaX);
ViewCompat.setTranslationY(newHolder.itemView, -deltaY);
ViewCompat.setAlpha(newHolder.itemView, 0);
}
mPendingChanges.add(new ChangeInfo(oldHolder, newHolder, fromX, fromY, toX, toY));
return true;
}