Example usage for android.view View setAlpha

List of usage examples for android.view View setAlpha

Introduction

In this page you can find the example usage for android.view View setAlpha.

Prototype

public void setAlpha(@FloatRange(from = 0.0, to = 1.0) float alpha) 

Source Link

Document

Sets the opacity of the view to a value from 0 to 1, where 0 means the view is completely transparent and 1 means the view is completely opaque.

Usage

From source file:com.suyonoion.loginexpanded.ExpandedViewpagerUI.java

public ExpandedViewpagerUI(Context context, AttributeSet attrs) {
    super(context, attrs);
    if (!isInEditMode()) {
        // array List string , daftar list judul
        List<String> mengisi_Tempat_judul = new ArrayList<>();
        /* judul page1/*from w  w  w .  java2 s  .  c  o  m*/
        * listjudul.tambahkan(dapakandarifolderRes.dapatkanStringDari(name="str_notifikasi",bertype="string")
        * */
        mengisi_Tempat_judul.add(getResources().getString(setResource("str_notifikasi", "string")));
        /* judul page2
        * listjudul.tambahkan(dapakandarifolderRes.dapatkanStringDari(name="str_page2",bertype="string")
        * */
        mengisi_Tempat_judul.add(getResources().getString(setResource("str_page2", "string")));
        /* judul page3
        * listjudul.tambahkan(dapakandarifolderRes.dapatkanStringDari(name="str_page3",bertype="string")
        * */
        mengisi_Tempat_judul.add(getResources().getString(setResource("str_page3", "string")));

        //mengisi_Tempat_judul masukkan ke adapter
        AdapterExpandedViewpagerUI adapter = new AdapterExpandedViewpagerUI(mengisi_Tempat_judul);
        // Viewpager id = temukan target view menurut id-nya
        final ViewPager EasyExpandedViewPagerUI = (ViewPager) this
                .findViewById(setResource("id_viewpager", "id"));
        // membuat pageTransformer/efek transisi
        PageTransformer animasi = new PageTransformer() {
            @TargetApi(Build.VERSION_CODES.HONEYCOMB) //target api
            @Override
            public void transformPage(View view, float position) {
                float ion = Float.valueOf("90"); //rotasi 90 derajat
                final float rotation = (position < 0 ? ion : -ion) * Math.abs(position);
                view.setAlpha(rotation > ion || rotation < -ion ? 0f : 1f);
                view.setPivotX(position < 0f ? view.getWidth() : 0f);
                view.setPivotY(view.getHeight() * 0.5f);
                view.setRotationY(ion * position);
            }
        };
        //setPageTransformer Viewpagernya = animasi
        EasyExpandedViewPagerUI.setPageTransformer(true, animasi);
        EasyExpandedViewPagerUI.setAdapter(adapter);
        EasyExpandedViewPagerUI.setOffscreenPageLimit(3); //jumlah limit pages = 3
    }
}

From source file:com.arthurpitman.common.SlidingPanel.java

@Override
public void computeScroll() {
    // work out correct scroll position
    int currentScrollY = 0;
    if (scroller.computeScrollOffset()) {
        currentScrollY = scroller.getCurrY();
        scrollTo(0, currentScrollY);//from w  w w .  j a  v a  2s  . c o  m
        invalidate();
    } else {
        currentScrollY = getScrollY();
    }

    // set alpha of views
    float alpha = (float) currentScrollY / viewHeight;
    View view1 = getChildAt(0);
    if (view1 != null) {
        view1.setAlpha(1 - alpha);
    }
    View view2 = getChildAt(1);
    if (view2 != null) {
        view2.setAlpha(alpha);
    }

    // update current view
    if (currentScrollY == 0) {
        currentView = COLLAPSED;
    } else if (currentScrollY == viewHeight) {
        currentView = EXPANDED;
    } else {
        currentView = TRANSITION;
    }
}

From source file:ca.farrelltonsolar.classic.MonthPager.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View theView = inflater.inflate(R.layout.day_logs_chart_pager, container, false);
    VerticalViewPager verticalViewPager = (VerticalViewPager) theView.findViewById(R.id.verticalviewpager);

    verticalViewPager.setAdapter(getAdapter());
    verticalViewPager.setPageMargin(getResources().getDimensionPixelSize(R.dimen.pagemargin));
    verticalViewPager//from ww  w  . j  ava 2 s.c  o m
            .setPageMarginDrawable(new ColorDrawable(getResources().getColor(android.R.color.holo_green_dark)));

    verticalViewPager.setPageTransformer(true, new ViewPager.PageTransformer() {
        @Override
        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.setTranslationY(vertMargin - horzMargin / 2);
                } else {
                    view.setTranslationY(-vertMargin + horzMargin / 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);
            }
        }
    });
    return theView;
}

From source file:com.alex.view.tab.TabLayout.java

/**
 * ? tab alpha transform  onPageScrolled ???
 *//*w w  w .ja va2s .  c  om*/
public void scrollTabTo(int position, float positionOffset) {
    if (position + 1 > mTabCount) {
        throw new IllegalArgumentException("position must be smaller than tabCount");
    }

    // onScroll: position = min(source, dest), positionOffset = [0, 1]
    // from 0 to 1: position = 0
    // from 1 to 0: position = 0
    View view;
    if (positionOffset > 0) {
        view = getChildAt(position);
        view.setAlpha(1 - positionOffset);
        view = getChildAt(position + 1);
        view.setAlpha(positionOffset);
    }
}

From source file:com.android.settings.PreviewPagerAdapter.java

private void setVisibility(final View view, final int visibility, boolean animate) {
    final float alpha = (visibility == View.VISIBLE ? 1.0f : 0.0f);
    if (!animate) {
        view.setAlpha(alpha);
        view.setVisibility(visibility);//  w w  w  . j a v  a2  s .  c  om
    } else {
        final Interpolator interpolator = (visibility == View.VISIBLE ? FADE_IN_INTERPOLATOR
                : FADE_OUT_INTERPOLATOR);
        if (visibility == View.VISIBLE) {
            // Fade in animation.
            view.animate().alpha(alpha).setInterpolator(FADE_IN_INTERPOLATOR)
                    .setDuration(CROSS_FADE_DURATION_MS).setListener(new PreviewFrameAnimatorListener())
                    .withStartAction(new Runnable() {
                        @Override
                        public void run() {
                            view.setVisibility(visibility);
                        }
                    });
        } else {
            // Fade out animation.
            view.animate().alpha(alpha).setInterpolator(FADE_OUT_INTERPOLATOR)
                    .setDuration(CROSS_FADE_DURATION_MS).setListener(new PreviewFrameAnimatorListener())
                    .withEndAction(new Runnable() {
                        @Override
                        public void run() {
                            view.setVisibility(visibility);
                        }
                    });
        }
    }
}

From source file:com.alex.view.tab.TabLayout.java

private void resetState() {
    View view;
    for (int i = 0; i < mTabCount; i++) {
        view = getChildAt(mCurrentTab);/*from ww w  .java  2s. c  o  m*/
        view.setAlpha(0);
    }
}

From source file:com.nikola.despotoski.drawerlayouttoggles.FadingDrawerToggle.java

@SuppressLint("NewApi")
@Override/* ww  w .  j ava2s .c om*/
public void onDrawerSlide(View drawerView, float slideOffset) {
    if (!mEnabled)
        return;
    float currentViewAlpha = slideOffset * MAX_VIEW_ALPHA;
    float currentDrawableAlpha = slideOffset * MAX_DRAWABLE_ALPHA;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        drawerView.setAlpha(currentViewAlpha);
    } else {
        AlphaAnimation alphaAnimation = new AlphaAnimation(mPreviousViewAlpha, currentViewAlpha);
        alphaAnimation.setFillAfter(true);
        alphaAnimation.setDuration(0);
        drawerView.startAnimation(alphaAnimation);
        mPreviousViewAlpha = currentViewAlpha;
    }
    drawerView.getBackground().setAlpha((int) currentDrawableAlpha);

}

From source file:com.yanzhenjie.recyclerview.swipe.widget.StickyNestedScrollView.java

private void hideView(View v) {
    v.setAlpha(0);
}

From source file:com.yanzhenjie.recyclerview.swipe.widget.StickyNestedScrollView.java

private void showView(View v) {
    v.setAlpha(1);
}

From source file:android.example.com.animationdemos.CrossfadeActivity.java

/**
 * Cross-fades between {@link #mContentView} and {@link #mLoadingView}.
 */// ww w.  j  ava  2  s  .com
private void showContentOrLoadingIndicator(boolean contentLoaded) {
    // Decide which view to hide and which to show.
    final View showView = contentLoaded ? mContentView : mLoadingView;
    final View hideView = contentLoaded ? mLoadingView : mContentView;
    // Set the "show" view to 0% opacity but visible, so that it is visible
    // (but fully transparent) during the animation.
    showView.setAlpha(0f);
    showView.setVisibility(View.VISIBLE);
    // Animate the "show" view to 100% opacity, and clear any animation listener set on
    // the view. Remember that listeners are not limited to the specific animation
    // describes in the chained method calls. Listeners are set on the
    // ViewPropertyAnimator object for the view, which persists across several
    // animations.
    showView.animate().alpha(1f).setDuration(mShortAnimationDuration).setListener(null);
    // Animate the "hide" view to 0% opacity. After the animation ends, set its visibility
    // to GONE as an optimization step (it won't participate in layout passes, etc.)
    hideView.animate().alpha(0f).setDuration(mShortAnimationDuration)
            .setListener(new AnimatorListenerAdapter() {
                @Override
                public void onAnimationEnd(Animator animation) {
                    hideView.setVisibility(View.GONE);
                }
            });
}