Example usage for android.view.animation TranslateAnimation TranslateAnimation

List of usage examples for android.view.animation TranslateAnimation TranslateAnimation

Introduction

In this page you can find the example usage for android.view.animation TranslateAnimation TranslateAnimation.

Prototype

public TranslateAnimation(float fromXDelta, float toXDelta, float fromYDelta, float toYDelta) 

Source Link

Document

Constructor to use when building a TranslateAnimation from code

Usage

From source file:com.flan.stock.view.NewsTabView.java

/**
 * ? ?//from ww w.j  a  v a  2  s . c o  m
 * @param position
 */
public void setCurrentTab(int position) {

    tv_tag1.setTextSize(14);
    tv_tag2.setTextSize(14);
    tv_tag3.setTextSize(14);
    tv_tag4.setTextSize(14);
    tv_tag5.setTextSize(14);

    switch (position) {
    case 0:
        tv_tag1.setTextSize(16);
        break;
    case 1:
        tv_tag2.setTextSize(16);
        break;
    case 2:
        tv_tag3.setTextSize(16);
        break;
    case 3:
        tv_tag4.setTextSize(16);
        break;
    case 4:
        tv_tag5.setTextSize(16);
        break;
    }

    Animation animation = null;
    animation = new TranslateAnimation(imgWidth * currentTab, imgWidth * position, 0, 0);
    animation.setFillAfter(true);//True:???
    animation.setDuration(300); //?
    img_cursor.startAnimation(animation);

    currentTab = position;

}

From source file:com.changhong.mscreensynergy.mainui.fragment.ViewPageFragment.java

public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    //mInflater = inflater;
    View mView = inflater.inflate(R.layout.view_pager, null);
    showLeft = (Button) mView.findViewById(R.id.showLeft);
    mPager = (ViewPager) mView.findViewById(R.id.pager);
    PageFragment1 page1 = new PageFragment1();
    PageFragment2 page2 = new PageFragment2();
    PageFragment3 page3 = new PageFragment3();
    //      PageFragment4 page4 = new PageFragment4();
    //      PageFragment5 page5 = new PageFragment5();
    pagerItemList.add(page1);//  www .j  ava 2 s .  com
    pagerItemList.add(page2);
    pagerItemList.add(page3);
    //      pagerItemList.add(page4);
    //      pagerItemList.add(page5);
    mAdapter = new MyAdapter(getFragmentManager());
    mPager.setAdapter(mAdapter);
    mPager.setOffscreenPageLimit(3); //3
    mPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {

        @Override
        public void onPageSelected(int position) {

            if (myPageChangeListener != null)
                myPageChangeListener.onPageSelected(position);

            if (rg_nav_content != null && rg_nav_content.getChildCount() > position) {
                ((RadioButton) rg_nav_content.getChildAt(position)).performClick();
            }

        }

        @Override
        public void onPageScrolled(int arg0, float arg1, int arg2) {

        }

        @Override
        public void onPageScrollStateChanged(int position) {

        }
    });

    /*
     * ?
     */
    rl_nav = (RelativeLayout) mView.findViewById(R.id.rl_nav);

    mHsv = (SyncHorizontalScrollView) mView.findViewById(R.id.mHsv);

    rg_nav_content = (RadioGroup) mView.findViewById(R.id.rg_nav_content);

    rg_nav_content.setOnCheckedChangeListener(new OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(RadioGroup group, int checkedId) {

            if (rg_nav_content.getChildAt(checkedId) != null) {

                TranslateAnimation animation = new TranslateAnimation(currentIndicatorLeft,
                        ((RadioButton) rg_nav_content.getChildAt(checkedId)).getLeft(), 0f, 0f);
                animation.setInterpolator(new LinearInterpolator());
                animation.setDuration(100);
                animation.setFillAfter(true);

                //?
                iv_nav_indicator.startAnimation(animation);

                mPager.setCurrentItem(checkedId); //ViewPager ? ?

                //? ? ?
                currentIndicatorLeft = ((RadioButton) rg_nav_content.getChildAt(checkedId)).getLeft();

                mHsv.smoothScrollTo(
                        (checkedId > 1 ? ((RadioButton) rg_nav_content.getChildAt(checkedId)).getLeft() : 0)
                                - ((RadioButton) rg_nav_content.getChildAt(2)).getLeft(),
                        0);
            }
        }
    });

    iv_nav_indicator = (ImageView) mView.findViewById(R.id.iv_nav_indicator);
    iv_nav_left = (ImageView) mView.findViewById(R.id.iv_nav_left);
    iv_nav_right = (ImageView) mView.findViewById(R.id.iv_nav_right);

    LayoutParams cursor_Params = iv_nav_indicator.getLayoutParams();
    cursor_Params.width = indicatorWidth;// ?
    iv_nav_indicator.setLayoutParams(cursor_Params);

    mHsv.setSomeParam(rl_nav, iv_nav_left, iv_nav_right, SlidingActivity.scontext);

    mInflater = (LayoutInflater) SlidingActivity.scontext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    indicatorWidth = SlidingMenu.screenWidth / 4;

    initNavigationHSV();

    return mView;
}

From source file:com.larswerkman.quickreturnlistview.BottomFragment.java

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    mListView = (QuickReturnListView) getListView();

    String[] array = new String[] { "Android", "Android", "Android", "Android", "Android", "Android", "Android",
            "Android", "Android", "Android", "Android", "Android", "Android", "Android", "Android", "Android" };

    setListAdapter(new ArrayAdapter<String>(getActivity(), R.layout.list_item, R.id.text1, array));

    mListView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
        @Override/*from   w w  w .j a va  2 s. c o  m*/
        public void onGlobalLayout() {
            mQuickReturnHeight = mQuickReturnView.getHeight();
            mListView.computeScrollY();
        }
    });

    mListView.setOnScrollListener(new OnScrollListener() {
        @SuppressLint("NewApi")
        @Override
        public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {

            mScrollY = 0;
            int translationY = 0;

            if (mListView.scrollYIsComputed()) {
                mScrollY = mListView.getComputedScrollY();
            }

            int rawY = mScrollY;

            switch (mState) {
            case STATE_OFFSCREEN:
                if (rawY >= mMinRawY) {
                    mMinRawY = rawY;
                } else {
                    mState = STATE_RETURNING;
                }
                translationY = rawY;
                break;

            case STATE_ONSCREEN:
                if (rawY > mQuickReturnHeight) {
                    mState = STATE_OFFSCREEN;
                    mMinRawY = rawY;
                }
                translationY = rawY;
                break;

            case STATE_RETURNING:

                translationY = (rawY - mMinRawY) + mQuickReturnHeight;

                System.out.println(translationY);
                if (translationY < 0) {
                    translationY = 0;
                    mMinRawY = rawY + mQuickReturnHeight;
                }

                if (rawY == 0) {
                    mState = STATE_ONSCREEN;
                    translationY = 0;
                }

                if (translationY > mQuickReturnHeight) {
                    mState = STATE_OFFSCREEN;
                    mMinRawY = rawY;
                }
                break;
            }

            /** this can be used if the build is below honeycomb **/
            if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.HONEYCOMB) {
                anim = new TranslateAnimation(0, 0, translationY, translationY);
                anim.setFillAfter(true);
                anim.setDuration(0);
                mQuickReturnView.startAnimation(anim);
            } else {
                mQuickReturnView.setTranslationY(translationY);
            }

        }

        @Override
        public void onScrollStateChanged(AbsListView view, int scrollState) {
        }
    });
}

From source file:com.marshalchen.common.demoofui.quickreturnlistview.BottomFragment.java

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    mListView = (QuickReturnListView) getListView();

    String[] array = new String[] { "Android", "Android", "Android", "Android", "Android", "Android", "Android",
            "Android", "Android", "Android", "Android", "Android", "Android", "Android", "Android", "Android" };

    setListAdapter(new ArrayAdapter<String>(getActivity(), R.layout.quick_return_listview_list_item, R.id.text1,
            array));//from ww  w. j a va 2s.co  m

    mListView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
        @Override
        public void onGlobalLayout() {
            mQuickReturnHeight = mQuickReturnView.getHeight();
            mListView.computeScrollY();
        }
    });

    mListView.setOnScrollListener(new OnScrollListener() {
        @SuppressLint("NewApi")
        @Override
        public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {

            mScrollY = 0;
            int translationY = 0;

            if (mListView.scrollYIsComputed()) {
                mScrollY = mListView.getComputedScrollY();
            }

            int rawY = mScrollY;

            switch (mState) {
            case STATE_OFFSCREEN:
                if (rawY >= mMinRawY) {
                    mMinRawY = rawY;
                } else {
                    mState = STATE_RETURNING;
                }
                translationY = rawY;
                break;

            case STATE_ONSCREEN:
                if (rawY > mQuickReturnHeight) {
                    mState = STATE_OFFSCREEN;
                    mMinRawY = rawY;
                }
                translationY = rawY;
                break;

            case STATE_RETURNING:

                translationY = (rawY - mMinRawY) + mQuickReturnHeight;

                System.out.println(translationY);
                if (translationY < 0) {
                    translationY = 0;
                    mMinRawY = rawY + mQuickReturnHeight;
                }

                if (rawY == 0) {
                    mState = STATE_ONSCREEN;
                    translationY = 0;
                }

                if (translationY > mQuickReturnHeight) {
                    mState = STATE_OFFSCREEN;
                    mMinRawY = rawY;
                }
                break;
            }

            /** this can be used if the build is below honeycomb **/
            if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.HONEYCOMB) {
                anim = new TranslateAnimation(0, 0, translationY, translationY);
                anim.setFillAfter(true);
                anim.setDuration(0);
                mQuickReturnView.startAnimation(anim);
            } else {
                mQuickReturnView.setTranslationY(translationY);
            }

        }

        @Override
        public void onScrollStateChanged(AbsListView view, int scrollState) {
        }
    });
}

From source file:freed.cam.ui.themesample.cameraui.HelpFragment.java

private void showCloseManualMenu() {
    TranslateAnimation animation = new TranslateAnimation(0.0f, 0.0f, 0.0f, 400.0f);
    animation.setDuration(1000);//from w  w w  .  j a v a 2  s.  c om
    animation.setRepeatCount(Animation.INFINITE);
    animation.setRepeatMode(Animation.INFINITE);
    animation.setFillAfter(true);
    finger.startAnimation(animation);
    description.setText(
            "Swipe from top to bottom to close Manuals\r\n\r\nif you can't the heat use Google camera :)");
    nextButton.setText("Close");
    dontshowagain.setVisibility(View.VISIBLE);
}

From source file:com.codefororlando.transport.MapsActivity.java

private void removeSelectableItemFragment() {
    final Fragment selectableItemFragment = getFragmentManager().findFragmentByTag(ISelectableItemFragment.TAG);
    if (selectableItemFragment != null) {
        final View view = selectableItemFragment.getView();
        if (view == null) {
            return;
        }/*from w ww .j av  a 2s  . co m*/

        final int animationDuration = getResources().getInteger(android.R.integer.config_shortAnimTime);

        {
            final Animation animation = new TranslateAnimation(0, 0, 0, view.getHeight());
            animation.setDuration(animationDuration);
            animation.setInterpolator(new AccelerateDecelerateInterpolator());
            filterView.startAnimation(animation);
        }
        {
            final FragmentManager fragmentManager = getFragmentManager();
            final Animation animation = new TranslateAnimation(0, 0, 0, view.getHeight());
            animation.setDuration(animationDuration);
            animation.setAnimationListener(new EmptyAnimationListener() {
                @Override
                public void onAnimationEnd(Animation animation) {
                    try {
                        fragmentManager.beginTransaction().remove(selectableItemFragment)
                                .commitAllowingStateLoss();
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            });
            view.startAnimation(animation);
        }
    }
}

From source file:com.cloverstudio.spika.SpikaApp.java

@Override
public void onCreate() {
    super.onCreate();
    sInstance = this;
    mPreferences = new Preferences(this);
    mPreferences.clearFlagsForTutorialEachBoot(getApplicationContext().getPackageName());
    gOpenFromBackground = true;//from   w w w.ja v a  2 s .  com
    mFileDir = new FileDir(this);

    ImageLoader.initImageLoaderInstance(this);

    mLocalBroadcastManager = LocalBroadcastManager.getInstance(this);

    // Create typefaces
    mTfMyriadPro = Typeface.createFromAsset(getAssets(), "fonts/Roboto-Regular.ttf");
    mTfMyriadProBold = Typeface.createFromAsset(getAssets(), "fonts/Roboto-Bold.ttf");

    setTransportBasedOnScreenDensity(42);

    // Example interpolator; could use linear or accelerate interpolator
    // instead
    final AccelerateDecelerateInterpolator accDecInterpolator = new AccelerateDecelerateInterpolator();
    final LinearInterpolator linearInterpolator = new LinearInterpolator();
    final int slidingDuration = getResources().getInteger(R.integer.sliding_duration);

    // Set up animations
    mSlideInLeft = new TranslateAnimation(-mTransport, 0, 0, 0);
    mSlideInLeft.setDuration(slidingDuration);
    // mSlideInLeft.setFillAfter(true); // hmm not sure
    mSlideInLeft.setFillEnabled(false);
    mSlideInLeft.setInterpolator(linearInterpolator);

    mSlideOutRight = new TranslateAnimation(0, mTransport, 0, 0);
    mSlideOutRight.setDuration(slidingDuration);
    mSlideOutRight.setFillAfter(true);
    mSlideOutRight.setFillEnabled(true);
    mSlideOutRight.setInterpolator(linearInterpolator);

    mSlideOutLeft = new TranslateAnimation(0, -mTransport, 0, 0);
    mSlideOutLeft.setDuration(slidingDuration);
    mSlideOutLeft.setInterpolator(linearInterpolator);

    mSlideInRight = new TranslateAnimation(mTransport, 0, 0, 0);
    mSlideInRight.setDuration(slidingDuration);
    mSlideInRight.setFillAfter(true);
    mSlideInRight.setFillEnabled(true);
    mSlideInRight.setInterpolator(linearInterpolator);

    mSlideFromTop.setFillAfter(true);
    mSlideFromTop.setFillEnabled(true);
    mSlideFromTop.setDuration(this.getResources().getInteger(android.R.integer.config_mediumAnimTime));
    mSlideFromTop.setInterpolator(linearInterpolator);

    mSlideOutTop.setDuration(this.getResources().getInteger(android.R.integer.config_mediumAnimTime));
    mSlideOutTop.setInterpolator(linearInterpolator);

    String strUUID = UUID.randomUUID().toString();
    Logger.debug("uuid", strUUID);

    mBaseUrl = mPreferences.getUserServerURL();
}

From source file:com.aidilab.ble.fragment.DrumSimpleFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    Log.i(TAG, "onCreateView");
    mInstance = this;
    mActivity = (FizzlyActivity) getActivity();

    // The last two arguments ensure LayoutParams are inflated properly.       
    View view = inflater.inflate(R.layout.fragment_drumsimple, container, false);

    //       mStatus    = (TextView) view.findViewById(R.id.status); 
    fizzlyImage = (ImageView) view.findViewById(R.id.imageViewFizzly);
    //       fizzlyImage.setOnClickListener(new OnClickListener() {
    //         /* ww  w.  j  ava  2  s .c o m*/
    //         @Override
    //         public void onClick(View v) {
    //            
    //            switch(count){
    //            case 0:
    //               Log.i(TAG, "0 left");
    //               startLeftAnimation();
    //               count++;
    //               break;
    //            case 1:
    //               Log.i(TAG, "1 right");
    //               startRightAnimation();
    //               count++;
    //               break;
    //            case 2:
    //               Log.i(TAG, "2 down");
    //               startDownAnimation();
    //               count=0;
    //               break;
    //            }
    //         }
    //      });

    leftAnimation = new TranslateAnimation(0f, -180F, 0f, 0f);
    leftAnimation.setDuration(250);
    //       leftAnimation.setInterpolator(new BounceInterpolator());

    rightAnimation = new TranslateAnimation(0f, 180F, 0f, 0f);
    rightAnimation.setDuration(250);
    //       rightAnimation.setInterpolator(new BounceInterpolator());

    downAnimation = new TranslateAnimation(0f, 0F, 0f, 200f);
    downAnimation.setDuration(250);
    //       downAnimation.setInterpolator(new BounceInterpolator());

    // Notify activity that UI has been inflated
    mActivity.onViewInflated(view);

    return view;
}

From source file:com.app.jdy.ui.LoginActivity.java

/**
 * //ww w. j a v  a  2s . c  om
 * @author Owater
 * @createtime 2015-1-13 ?6:05:11
 * @Decription ??
 * 
 */
public void intiAnimation() {
    // 
    // Animation translateAnimation = AnimationUtils.loadAnimation(this,
    // R.anim.translate_username);
    Animation translateAnimation1 = new TranslateAnimation(0, 0, 3000, 0);
    translateAnimation1.setDuration(1200);// ?
    // username_message.startAnimation(translateAnimation1);

    Animation translateAnimation2 = new TranslateAnimation(0, 0, 3000, 0);
    translateAnimation2.setDuration(1400);// ?
    // password_message.startAnimation(translateAnimation2);

    Animation translateAnimation3 = new TranslateAnimation(0, 0, 3000, 0);
    translateAnimation3.setDuration(1600);// ?
    sumbitLogin.startAnimation(translateAnimation3);
    loginOther.startAnimation(translateAnimation3);
    loginWeixin.startAnimation(translateAnimation3);

    Animation translateAnimation4 = new TranslateAnimation(0, 0, 3000, 0);
    translateAnimation4.setDuration(1800);// ?
    find_password.startAnimation(translateAnimation4);
    regirster.startAnimation(translateAnimation4);

    // ??
    // Animation animation =AnimationUtils.loadAnimation(this,
    // R.anim.animation_image_logo);
    Animation animation = new AlphaAnimation(0F, 1.0F);
    animation.setDuration(5000);
    // logoImage.startAnimation(animation);
    animation.startNow();

    /*
     * Animation scaleAnimation = new ScaleAnimation(1.0f, 1.0f, 4.0f, 1.0f,
     * Animation.RELATIVE_TO_SELF, 1.0f, Animation.RELATIVE_TO_SELF, 1.0f);
     * scaleAnimation.setDuration(2000);
     * logoImage.startAnimation(scaleAnimation); scaleAnimation.startNow();
     */
}

From source file:cn.eoe.wiki.view.SliderLayer.java

public void closeSidebar(int index) {
    if (index != mOpenLayerIndex) {
        L.e("Can`t close the layer which is not opening");
        return;//ww  w. j a v a2 s. co  m
    }
    SliderEntity layer = mListLayers.get(index);
    if (layer.view.getAnimation() != null) {
        return;
    }
    mAnimation = new TranslateAnimation(0, (layer.closeX - layer.openX), 0, 0);
    mAnimation.setAnimationListener(new CloseListener(layer.view));

    mAnimation.setDuration(DURATION);
    mAnimation.setFillAfter(true);
    mAnimation.setFillEnabled(true);

    mOpenLayerIndex--;
    layer.view.startAnimation(mAnimation);
}