Android中如何實(shí)現(xiàn)動(dòng)畫自動(dòng)播放功能

這篇文章主要介紹“Android中如何實(shí)現(xiàn)動(dòng)畫自動(dòng)播放功能”,在日常操作中,相信很多人在Android中如何實(shí)現(xiàn)動(dòng)畫自動(dòng)播放功能問(wèn)題上存在疑惑,小編查閱了各式資料,整理出簡(jiǎn)單好用的操作方法,希望對(duì)大家解答”Android中如何實(shí)現(xiàn)動(dòng)畫自動(dòng)播放功能”的疑惑有所幫助!接下來(lái),請(qǐng)跟著小編一起來(lái)學(xué)習(xí)吧!

專注于為中小企業(yè)提供成都網(wǎng)站建設(shè)、成都網(wǎng)站設(shè)計(jì)服務(wù),電腦端+手機(jī)端+微信端的三站合一,更高效的管理,為中小企業(yè)樂陵免費(fèi)做網(wǎng)站提供優(yōu)質(zhì)的服務(wù)。我們立足成都,凝聚了一批互聯(lián)網(wǎng)行業(yè)人才,有力地推動(dòng)了上千家企業(yè)的穩(wěn)健成長(zhǎng),幫助中小企業(yè)通過(guò)網(wǎng)站建設(shè)實(shí)現(xiàn)規(guī)模擴(kuò)充和轉(zhuǎn)變。

具體如下:

private ImageView image;
private AnimationDrawable animDrawable = new AnimationDrawable();
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.table_title);
    image = (ImageView) this.findViewById(R.id.scrollView);
    //代碼實(shí)現(xiàn)
//   for(int i=0; i<16; i++){
//     int id = getResources().getIdentifier("load_"+(i+1), "drawable", getPackageName());
//     animDrawable.addFrame(getResources().getDrawable(id), 50);
//   }
//   animDrawable.setOneShot(false);
//   image.setBackgroundDrawable(animDrawable);
    animDrawable = (AnimationDrawable) image.getBackground();
}
@Override
public void onWindowFocusChanged(boolean hasFocus) {
    super.onWindowFocusChanged(hasFocus);
    animDrawable.start();
}

在onCreate中執(zhí)行 animDrawale.start() 動(dòng)畫并不執(zhí)行。 搞不懂啊
另外以上代碼測(cè)試過(guò)有缺陷。 例如在TabActivity中 onWindowFocusChanged只會(huì)執(zhí)行一次

所以

AnimationDrawable ad;
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    ImageView iv = (ImageView) findViewById(R.id.animation_view);
    iv.setBackgroundResource(R.drawable.animation);
    ad = (AnimationDrawable) iv.getBackground();
   //關(guān)鍵代碼
   iv.getViewTreeObserver().addOnPreDrawListener(opdl);
}
OnPreDrawListener opdl=new OnPreDrawListener(){
    @Override
    public boolean onPreDraw() {
        if(ad.isRunning() == false){
        ad.start();
        }
        return true; //注意必須返回true
    }
};

到此,關(guān)于“Android中如何實(shí)現(xiàn)動(dòng)畫自動(dòng)播放功能”的學(xué)習(xí)就結(jié)束了,希望能夠解決大家的疑惑。理論與實(shí)踐的搭配能更好的幫助大家學(xué)習(xí),快去試試吧!若想繼續(xù)學(xué)習(xí)更多相關(guān)知識(shí),請(qǐng)繼續(xù)關(guān)注創(chuàng)新互聯(lián)網(wǎng)站,小編會(huì)繼續(xù)努力為大家?guī)?lái)更多實(shí)用的文章!

本文標(biāo)題:Android中如何實(shí)現(xiàn)動(dòng)畫自動(dòng)播放功能
分享鏈接:http://bm7419.com/article14/geijde.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供手機(jī)網(wǎng)站建設(shè)、網(wǎng)站設(shè)計(jì)公司面包屑導(dǎo)航、網(wǎng)站制作企業(yè)建站

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

h5響應(yīng)式網(wǎng)站建設(shè)