Java Code Examples for android.view.View#setAlpha()

The following examples show how to use android.view.View#setAlpha() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StickyListAdapter.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
@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;
}
 
Example 2
Source File: ExpandableViewHoldersUtil.java    From Ticket-Analysis with MIT License 6 votes vote down vote up
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);
    }
}
 
Example 3
Source File: ABaseTransformer.java    From PowerFileExplorer with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 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);
	}
}
 
Example 4
Source File: PickerLayoutManager.java    From AndroidProject with Apache License 2.0 6 votes vote down vote up
/**
 * 横向情况下的缩放
 */
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);
            }
        }
    }
}
 
Example 5
Source File: BlurActionBarDrawerToggle.java    From BlurNavigationDrawer with Apache License 2.0 5 votes vote down vote up
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);
    }
}
 
Example 6
Source File: UDView.java    From VideoOS-Android-SDK with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 设置view的alpha
 */
public UDView setAlpha(float alpha) {
    View view = getView();
    if (view != null) {
        view.setAlpha(alpha);
    }
    return this;
}
 
Example 7
Source File: TransformItemDecoration.java    From weex-uikit with MIT License 5 votes vote down vote up
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));
  }

}
 
Example 8
Source File: SimplePageTransformer.java    From NanoIconPack with Apache License 2.0 5 votes vote down vote up
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);
    }
}
 
Example 9
Source File: Overview.java    From Trebuchet with GNU General Public License v3.0 5 votes vote down vote up
@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);
}
 
Example 10
Source File: SpinnerTransformation.java    From Android-Image-Slider with Apache License 2.0 5 votes vote down vote up
@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);

    }


}
 
Example 11
Source File: FlipVerticalTransformer.java    From Banner with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example 12
Source File: DepthTransFormes.java    From MoeQuest with Apache License 2.0 5 votes vote down vote up
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);
    }
  }
 
Example 13
Source File: SliderHelper.java    From hr with GNU Affero General Public License v3.0 5 votes vote down vote up
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);
    }
}
 
Example 14
Source File: AnimHelper.java    From mvvm-template with GNU General Public License v3.0 5 votes vote down vote up
@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);
    }
}
 
Example 15
Source File: AlphaAnimator.java    From android-md-core with Apache License 2.0 5 votes vote down vote up
@Override
public void onAnimationUpdate(ValueAnimator animation) {
  View target = mTarget.get();
  if (target != null) {
    float alpha = (float) animation.getAnimatedValue();
    target.setAlpha(alpha);
  }
}
 
Example 16
Source File: MultiFloatingActionButton.java    From ReadMark with Apache License 2.0 5 votes vote down vote up
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();
    }
}
 
Example 17
Source File: ConversationSwipeAnimationHelper.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
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);
  }
}
 
Example 18
Source File: FadeOut.java    From android-ConstraintLayoutExamples with Apache License 2.0 4 votes vote down vote up
@Override
public void setProgress(View view, float progress) {
    view.setAlpha(1f - progress);
}
 
Example 19
Source File: ViewCompatHC.java    From adt-leanback-support with Apache License 2.0 4 votes vote down vote up
public static void setAlpha(View view, float value) {
    view.setAlpha(value);
}
 
Example 20
Source File: AlphaProperty.java    From WIFIADB with Apache License 2.0 4 votes vote down vote up
@Override
public void set(View object, Float value) {
    object.setAlpha(value);
}