android studio 2.1.2中的动画Gif

时间:2016-08-05 22:32:52

标签: java android-studio animated-gif

我刚刚升级到2.1.2 android studio,我试图在我的项目中添加动画gif,运行应用程序时出错,我向你展示MainActivity.class,Second class和Manifest。 / p>

应用程序只是立即关闭,android studio说在我的类MainActivity中启动应用程序时出现问题:$ adb shell am start -n" com.example.compushop.gifanimado / com.example.compushop.gifanimado.MainActivity" -a -c android.intent.action.MAIN android.intent.category.LAUNCHER,它是否会更新Android Studio?更新它,因为我遇到这个问题,无法编译应用程序,我希望你能帮助我。

这是错误:

08-05 17:11:37.518 3299-3299/? E/AndroidRuntime: FATAL EXCEPTION: main
                                             java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.compushop.gifanimado/com.example.compushop.gifanimado.MainActivity}: android.content.res.Resources$NotFoundException: File res/drawable/abc_ic_ab_back_material.xml from drawable resource ID #0x7f020013
                                                 at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
                                                 at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
                                                 at android.app.ActivityThread.access$600(ActivityThread.java:141)
                                                 at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
                                                 at android.os.Handler.dispatchMessage(Handler.java:99)
                                                 at android.os.Looper.loop(Looper.java:137)
                                                 at android.app.ActivityThread.main(ActivityThread.java:5041)
                                                 at java.lang.reflect.Method.invokeNative(Native Method)
                                                 at java.lang.reflect.Method.invoke(Method.java:511)
                                                 at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
                                                 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
                                                 at dalvik.system.NativeStart.main(Native Method)
                                              Caused by: android.content.res.Resources$NotFoundException: File res/drawable/abc_ic_ab_back_material.xml from drawable resource ID #0x7f020013
                                                 at android.content.res.Resources.loadDrawable(Resources.java:1953)
                                                 at android.content.res.Resources.getDrawable(Resources.java:660)
                                                 at android.support.v4.content.ContextCompat.getDrawable(ContextCompat.java:354)
                                                 at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:193)
                                                 at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:181)
                                                 at android.support.v7.widget.AppCompatDrawableManager.checkVectorDrawableSetup(AppCompatDrawableManager.java:689)
                                                 at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:186)
                                                 at android.support.v7.widget.TintTypedArray.getDrawableIfKnown(TintTypedArray.java:77)
                                                 at android.support.v7.app.AppCompatDelegateImplBase.<init>(AppCompatDelegateImplBase.java:83)
                                                 at android.support.v7.app.AppCompatDelegateImplV7.<init>(AppCompatDelegateImplV7.java:146)
                                                 at android.support.v7.app.AppCompatDelegateImplV11.<init>(AppCompatDelegateImplV11.java:28)
                                                 at android.support.v7.app.AppCompatDelegateImplV14.<init>(AppCompatDelegateImplV14.java:41)
                                                 at android.support.v7.app.AppCompatDelegate.create(AppCompatDelegate.java:193)
                                                 at android.support.v7.app.AppCompatDelegate.create(AppCompatDelegate.java:173)
                                                 at android.support.v7.app.AppCompatActivity.getDelegate(AppCompatActivity.java:511)
                                                 at android.support.v7.app.AppCompatActivity.onCreate(AppCompatActivity.java:71)
                                                 at com.example.compushop.gifanimado.MainActivity.onCreate(MainActivity.java:13)
                                                 at android.app.Activity.performCreate(Activity.java:5104)
                                                 at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
                                                 at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
                                                 at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230) 
                                                 at android.app.ActivityThread.access$600(ActivityThread.java:141) 
                                                 at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234) 
                                                 at android.os.Handler.dispatchMessage(Handler.java:99) 
                                                 at android.os.Looper.loop(Looper.java:137) 
                                                 at android.app.ActivityThread.main(ActivityThread.java:5041) 
                                                 at java.lang.reflect.Method.invokeNative(Native Method) 
                                                 at java.lang.reflect.Method.invoke(Method.java:511) 
                                                 at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793) 
                                                 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560) 
                                                 at dalvik.system.NativeStart.main(Native Method) 
                                              Caused by: org.xmlpull.v1.XmlPullParserException: Binary XML file line #17: invalid drawable tag vector
                                                 at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:881)
                                                 at android.graphics.drawable.Drawable.createFromXml(Drawable.java:822)
                                                 at android.content.res.Resources.loadDrawable(Resources.java:1950)
                                                 at android.content.res.Resources.getDrawable(Resources.java:660) 
                                                 at android.support.v4.content.ContextCompat.getDrawable(ContextCompat.java:354) 
                                                 at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:193) 
                                                 at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:181) 
                                                 at android.support.v7.widget.AppCompatDrawableManager.checkVectorDrawableSetup(AppCompatDrawableManager.java:689) 
                                                 at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:186) 
                                                 at android.support.v7.widget.TintTypedArray.getDrawableIfKnown(TintTypedArray.java:77) 
                                                 at android.support.v7.app.AppCompatDelegateImplBase.<init>(AppCompatDelegateImplBase.java:83) 
                                                 at android.support.v7.app.AppCompatDelegateImplV7.<init>(AppCompatDelegateImplV7.java:146) 
                                                 at android.support.v7.app.AppCompatDelegateImplV11.<init>(AppCompatDelegateImplV11.java:28) 
                                                 at android.support.v7.app.AppCompatDelegateImplV14.<init>(AppCompatDelegateImplV14.java:41) 
                                                 at android.support.v7.app.AppCompatDelegate.create(AppCompatDelegate.java:193) 
                                                 at android.support.v7.app.AppCompatDelegate.create(AppCompatDelegate.java:173) 
                                                 at android.support.v7.app.AppCompatActivity.getDelegate(AppCompatActivity.java:511) 
                                                 at android.support.v7.app.AppCompatActivity.onCreate(AppCompatActivity.java:71) 
                                                 at com.example.compushop.gifanimado.MainActivity.onCreate(MainActivity.java:13) 
                                                 at android.app.Activity.performCreate(Activity.java:5104) 
                                                 at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080) 
                                                 at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144) 
                                                 at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230) 
                                                 at android.app.ActivityThread.access$600(ActivityThread.java:141) 
                                                 at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234) 
                                                 at android.os.Handler.dispatchMessage(Handler.java:99) 
                                                 at android.os.Looper.loop(Looper.java:137) 
                                                 at android.app.ActivityThread.main(ActivityThread.java:5041) 
                                                 at java.lang.reflect.Method.invokeNative(Native Method) 
                                                 at java.lang.reflect.Method.invoke(Method.java:511) 
                                                 at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793) 
                                                 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560) 
                                                 at dalvik.system.NativeStart.main(Native Method) 

这是我的MainActivity:

package com.example.compushop.gifanimado;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {

TextView textViewInfo;
VistaGif vistaGif;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    vistaGif = (VistaGif)findViewById(R.id.vistagif);
    textViewInfo = (TextView)findViewById(R.id.textinfo);

    String stringInfo ="";
    stringInfo += "Duracion: " + vistaGif.getMovieDuration() + "\n";
    stringInfo += "W x H: " + vistaGif.getMovieWidht() + " x "  + vistaGif.getMovieHeight() + "\n";

    textViewInfo.setText(stringInfo);
}
}

另一堂课:

package com.example.compushop.gifanimado;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Movie;
import android.os.SystemClock;
import android.util.AttributeSet;
import android.view.View;

import java.io.InputStream;

/**
* Created by Compu Shop on 05/08/2016.
*/
public class VistaGif extends View {

private InputStream gifInputStream;
private Movie gifMovie;
private int movieWidht, movieHeight;
private long movieDuration, movieStart;


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

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

}

public VistaGif(Context context, AttributeSet attrs, int defStyleAttr){
    super(context, attrs, defStyleAttr);
    init(context);

}

private void init(Context context){
    setFocusable(true);

    gifInputStream = context.getResources().openRawResource(+R.drawable.arrastre);

    gifMovie = Movie.decodeStream(gifInputStream);
    movieWidht = gifMovie.width();
    movieHeight = gifMovie.height();
    movieDuration = gifMovie.duration();
}

@Override
protected void onMeasure(int widhtMeasureSpec, int heightMeasureSpec){
    setMeasuredDimension(movieWidht, movieHeight);

}

public int getMovieWidht(){
    return movieWidht;
}

public int getMovieHeight(){
    return movieHeight;
}

public long getMovieDuration(){
    return movieDuration;
}

@Override
protected void onDraw(Canvas canvas) {

    long now = SystemClock.uptimeMillis();

    if(movieStart == 0){
        movieStart = now;
    }

    if (gifMovie != null){

        int dur = gifMovie.duration();
        if(dur == 0){
            dur = 1000;
        }

        int relTime = (int)((now - movieStart) % dur);

        gifMovie.setTime(relTime);
        gifMovie.draw(canvas, 0, 0);
        invalidate();
    }
}
}

我的宣言:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.compushop.gifanimado">

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity android:name=".MainActivity"
        android:hardwareAccelerated="false">

        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

</manifest>

0 个答案:

没有答案