2012-01-04 15 views
15

का उपयोग कर मुझे एक स्प्लैश पेज के लिए काम करने के लिए एनिमेटेड लोडिंग स्पिनर प्राप्त करने में थोड़ी परेशानी हो रही है। जब मैं निम्नलिखित कोड चलाने की कोशिश करता हूं तो कुछ भी दिखाई नहीं देता है। कोई सुझाव? ऐसा लगता है कि बहुत से लोगों को Google पर इसके साथ समस्याएं हैं लेकिन मुझे समझ में नहीं आता कि मेरा काम क्यों विफल रहा है। धन्यवाद!एंड्रॉइड एनीमेशन-सूची

animationloader.xml

<?xml version="1.0" encoding="utf-8"?> 
<animation-list xmlns:android="http://schemas.android.com/apk/res/android" 
android:oneshot="false"> 
<item android:drawable="@drawable/loadingspinner1" android:duration="200" /> 
<item android:drawable="@drawable/loadingspinner2" android:duration="200" /> 
<item android:drawable="@drawable/loadingspinner3" android:duration="200" /> 
<item android:drawable="@drawable/loadingspinner4" android:duration="200" /> 
<item android:drawable="@drawable/loadingspinner5" android:duration="200" /> 
<item android:drawable="@drawable/loadingspinner6" android:duration="200" /> 
<item android:drawable="@drawable/loadingspinner7" android:duration="200" /> 
<item android:drawable="@drawable/loadingspinner8" android:duration="200" /> 
<item android:drawable="@drawable/loadingspinner9" android:duration="200" /> 
<item android:drawable="@drawable/loadingspinner01" android:duration="200" /> 
<item android:drawable="@drawable/loadingspinner11" android:duration="200" /> 
<item android:drawable="@drawable/loadingspinner12" android:duration="200" /> 
</animation-list> 

SplashScreen.java

package com.secure.inmatecanteen; 

import android.app.Activity; 
import android.graphics.drawable.AnimationDrawable; 
import android.os.Bundle; 
import android.widget.ImageView; 

public class SplashScreen extends Activity { 

@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.splashscreen); 

    //Beginning the loading animation as we attempt to verify registration with SIP 
    ImageView ivLoader = (ImageView) findViewById(R.id.IVloadinganimation); 
    ivLoader.setBackgroundResource(R.anim.animationloader); 


    AnimationDrawable frameAnimation = (AnimationDrawable) ivLoader.getBackground(); 
    frameAnimation.start(); 
} 
} 

splashscreen.xml

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:orientation="horizontal" 
android:background="@android:color/white" > 

<ImageView 
android:id="@+id/iclogo" 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:layout_gravity="center" 
android:src="@drawable/iclogo" 
android:adjustViewBounds="true" 
/> 

<ImageView 
android:id="@+id/IVloadinganimation" 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:layout_gravity="center" 
android:adjustViewBounds="true" 
/> 

    </LinearLayout> 
+0

यू पर इस गतिविधि शामिल है manifest.xml फाइल ई? – sampathpremarathna

+0

हां मेरे पास है। एनीमेशन – tier1

उत्तर

22

अपने ही समस्या हल, आप OnCreate में एनिमेशन शुरू नहीं कर सकते। यह एक ऑनक्लिक श्रोता या एक रननेबल के अंदर होना चाहिए।

+4

के बिना गतिविधि प्रदर्शित करता है लेकिन मेरा काम ऑनक्रिकेट पर काम करता है, लेकिन ऑनक्लिक पर नहीं। –

+3

http://developer.android.com/guide/topics/graphics/drawable-animation.html के अनुसार आपको इसे कभी भी क्रेट() पर कॉल नहीं करना चाहिए। – rude

4

आप onWindowFocusChanged(boolean hasFocus) विधि से animation खेल सकते/शुरू कर सकते हैं।

15

मुझे लगता है कि सबसे सुंदर और बहुमुखी विकल्प imageView वर्ग से विस्तार करने के लिए है:

public class Loader extends ImageView { 

    public Loader(Context context, AttributeSet attrs, int defStyle) { 
     super(context, attrs, defStyle); 
     init(); 
    } 

    public Loader(Context context, AttributeSet attrs) { 
     super(context, attrs); 
     init(); 
    } 

    public Loader(Context context) { 
     super(context); 
     init(); 
    } 

    private void init() { 
     setBackgroundResource(R.drawable.loader); 
     final AnimationDrawable frameAnimation = (AnimationDrawable) getBackground(); 
     post(new Runnable(){ 
      public void run(){ 
       frameAnimation.start(); 
      } 
     }); 
    } 
} 

loader.xml drawable फ़ोल्डर में स्थित:

<?xml version="1.0" encoding="utf-8"?> 
    <animation-list xmlns:android="http://schemas.android.com/apk/res/android" > 
    <item android:drawable="@drawable/loader_1" android:duration="50" /> 
    <item android:drawable="@drawable/loader_2" android:duration="50" /> 
    <item android:drawable="@drawable/loader_3" android:duration="50" /> 
    <item android:drawable="@drawable/loader_4" android:duration="50" /> 
    ..... 
</animation-list> 

अब अपने विचार कुछ में शामिल हैं इस तरह के रूप में सरल:

<com.yourpackage.Loader 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" /> 
+0

में 3 डिवाइस थे, केवल इसे एंड्रॉइड 4.2.2 चलाने वाले नेक्सस 4 पर काम करने के लिए मिल सकता था, हनीकॉम या जिंजरब्रेड डिवाइस पर काम नहीं किया था। शायद व्यूफ्लिपर्स – CQM

+0

के साथ चिपकना होगा, मैंने हनीकॉम और जिंजरब्रेड के साथ संगतता जोड़ने में इनिट विधि अपडेट की है। इसे जाँचे। –

+0

एक आकर्षण की तरह काम करता है, धन्यवाद! – CQM

2

इस हैंडलर में एनीमेशन पूरी तरह से टी से जुड़ा नहीं है वह खिड़की, तो एनिमेशन शुरू नहीं किया जा सकता है; इसके बजाए, यह आम तौर पर उपयोगकर्ता कार्रवाई (जैसे बटन प्रेस) के परिणामस्वरूप या onWindowFocusChangedhandler के परिणामस्वरूप किया जाता है।

देखें: पेशेवर एंड्रॉयड 4 अनुप्रयोग विकास

0

एक्सएमएल कोड में छवि संसाधन सेट न करें।

मेरे एक्सएमएल है:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
android:layout_width="match_parent" 
android:gravity="center" 
android:keepScreenOn="true" 
android:id="@+id/splashLayout" 
android:background="@color/colorPrimary" 
android:layout_height="match_parent"> 


<ImageView 
    android:layout_width="230dp" 
    android:layout_height="230dp" 
    android:id="@+id/iv_splash" 
    android:layout_marginTop="-80dp" 
    android:layout_centerVertical="true" 
    android:layout_centerHorizontal="true" /> 


</RelativeLayout> 

गतिविधि में मैं

public class SplashActivity extends Activity { 

ImageView iv_splash; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_splash); 

    iv_splash=(ImageView)findViewById(R.id.iv_splash); 
    iv_splash.setBackgroundResource(R.drawable.splash); 
    final AnimationDrawable progressAnimation =(AnimationDrawable)iv_splash.getBackground(); 
    progressAnimation.start(); 
    } 
} 

Drawable फ़ाइल कर

<?xml version="1.0" encoding="utf-8"?> 
<animation-list xmlns:android="http://schemas.android.com/apk/res/android" 
android:oneshot="false" > 

<item android:drawable="@drawable/logo" android:duration="400"/> 
<item android:drawable="@drawable/logo1" android:duration="400"/> 

</animation-list> 

यह काम कर रहा अच्छा :)