Android 控制項的顯示隱藏上下左右移動動畫,android控制項

來源:互聯網
上載者:User

Android 控制項的顯示隱藏上下左右移動動畫,android控制項

一、利用Android提供的左右移動工具類:AnimationUtils

    LinearLayout ll_first = (LinearLayout) findViewById(R.id.ll_first);    LinearLayout ll_second = (LinearLayout) findViewById(R.id.ll_second);    ll_first.setVisibility(View.GONE);    ll_second.setVisibility(View.VISIBLE);    // 向右邊移出    ll_first.setAnimation(AnimationUtils.makeOutAnimation(this, true));    // 向右邊移入    ll_second.setAnimation(AnimationUtils.makeInAnimation(this, true));                ll_first.setVisibility(View.VISIBLE);    ll_second.setVisibility(View.GONE);    // 向左邊移入    ll_first.setAnimation(AnimationUtils.makeInAnimation(this, false));    // 向左邊移出    ll_second.setAnimation(AnimationUtils.makeOutAnimation(this, false));

二、用TranslateAnimation添加動畫

先寫一個AnimationUtil工具類:這裡僅提供上下移動效果

public class AnimationUtil {    private static final String TAG = AnimationUtil.class.getSimpleName();    /**     * 從控制項所在位置移動到控制項的底部     *     * @return     */    public static TranslateAnimation moveToViewBottom() {        TranslateAnimation mHiddenAction = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0.0f,                Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF,                0.0f, Animation.RELATIVE_TO_SELF, 1.0f);        mHiddenAction.setDuration(500);        return mHiddenAction;    }    /**     * 從控制項的底部移動到控制項所在位置     *     * @return     */    public static TranslateAnimation moveToViewLocation() {        TranslateAnimation mHiddenAction = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0.0f,                Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF,                1.0f, Animation.RELATIVE_TO_SELF, 0.0f);        mHiddenAction.setDuration(500);        return mHiddenAction;    }}

隱藏的時候設定下動畫就可以了

                ll_first.setVisibility(View.GONE);                ll_second.setVisibility(View.VISIBLE);                ll_first.setAnimation(AnimationUtil.moveToViewBottom());                ll_second.setAnimation(AnimationUtil.moveToViewLocation());

部落格原文地址:http://www.cnblogs.com/liqw/p/4602876.html

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.