Show .gif with android.graphics.Movie

前端 未结 3 1429
夕颜
夕颜 2021-02-01 06:46

I\'m trying, create a view with an animated GIF..

When i try run the follow code in emulator all works fine. But when i try run in real Smart Phone, nothing happens..

相关标签:
3条回答
  • 2021-02-01 07:21

    Don't turn off hardware acceleration for the whole application. That's crippling. Just turn it off for the view:

    setLayerType(View.LAYER_TYPE_SOFTWARE, null);
    
    0 讨论(0)
  • 2021-02-01 07:22

    Loading an animated GIF seems tricky, but I would suggest to use a WebView as an alternative.

    Do as follow to resolve the problem :

    1. Copy your GIF in Android Assets.
    2. Call webView.loadDataWithBaseURL("file:///android_asset/", "", "text/html", "utf-8", null);

    I hope it helps !

    0 讨论(0)
  • 2021-02-01 07:23

    I dont think the Movie object works correctly on devices where hardware acceleration is turned on (which is turned on by default in Android 4.x for devices that support it. Your emulator may not.)

    Try adding

     android:hardwareAccelerated="false"
    

    to the activity definition for MainActivity in AndroidManifest.xml

    Example:

    <activity
        android:name=".MainActivity"
        android:hardwareAccelerated="false"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
    
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    
    0 讨论(0)
提交回复
热议问题