簡體   English   中英

在Android API 16中膨脹類BezelImageView時出錯,但在API 23中工作?

[英]Error Inflating Class BezelImageView in android api 16 but working in api 23?

我正在嘗試使用github上 google iosched 2015應用程序中的Navigation抽屜。 我還創建了我的BaseActivity類和navdrawer.xml類。

我已經將BaseActivity擴展到了HomeActivity。 HomeActivity的布局代碼為

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="windo.com.wind_o.HomeScreen">

    <!--<include layout="@layout/tool_bar"></include>-->



    <ImageView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:scaleType="centerCrop"

        android:id="@+id/imageView"
        android:src="@drawable/home_page_one"




        android:layout_alignParentLeft="false" />
    <android.support.design.widget.AppBarLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/app_bar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/ThemeOverlay.AppCompat.ActionBar">
        <android.support.v7.widget.Toolbar
            android:id="@+id/tool_bar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            app:theme="@style/ToolbarTheme"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
            app:layout_collapseMode="pin"
            style="@style/Base.ThemeOverlay.AppCompat.Dark.ActionBar" />

    </android.support.design.widget.AppBarLayout>

    <!--<TextView-->
        <!--android:id="@+id/txtview1"-->
        <!--android:layout_width="match_parent"-->
        <!--android:background="#a0000000"-->
        <!--android:layout_height="60dp"-->
        <!--android:textSize="24sp"-->
        <!--android:gravity="center_vertical|center_horizontal"-->
        <!--android:singleLine="true"-->
        <!--android:text="WIND-O"-->
        <!--android:textStyle="bold"-->
        <!--android:textColor="@color/ColorPrimary" />-->

    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:paddingRight="@dimen/activity_horizontal_margin"
        android:layout_marginTop="32dp"
        android:paddingLeft="@dimen/activity_horizontal_margin"
        android:layout_marginBottom="32dp"
        android:layout_alignParentBottom="true"
        android:gravity="bottom"
        android:layout_height="match_parent"

  >

        <!--<Button-->
            <!--android:layout_width="match_parent"-->
            <!--android:layout_height="40dp"-->

            <!--android:text="CATEGORIES"-->
            <!--android:background="@drawable/transparent_with_white_border"-->

            <!--android:id="@+id/categoryBtn"-->
            <!--android:layout_marginBottom="6dp"-->
            <!--android:textColor="@color/ColorPrimary"-->
            <!--android:layout_gravity="center"-->
            <!--android:textSize="18sp"-->
            <!--android:gravity="center_vertical|center_horizontal"-->
            <!--android:textStyle="bold"-->
            <!--android:typeface="monospace" />-->

        <!--<Button-->
            <!--android:layout_width="match_parent"-->
            <!--android:layout_height="40dp"-->
            <!--android:text="TRENDING"-->
            <!--android:background="@drawable/transparent_with_white_border"-->
            <!--android:id="@+id/home_btn_2"-->
            <!--android:layout_marginBottom="6dp"-->
            <!--android:textColor="@color/ColorPrimary"-->
            <!--android:layout_gravity="center"-->
            <!--android:textSize="18sp"-->
            <!--android:gravity="center_vertical|center_horizontal"-->
            <!--android:textStyle="bold"-->
            <!--android:typeface="monospace"/>-->

        <!--<Button-->
            <!--android:layout_width="match_parent"-->
            <!--android:layout_height="40dp"-->
            <!--android:text="DISCOVER"-->
            <!--android:background="@drawable/transparent_with_white_border"-->
            <!--android:id="@+id/discover_btn"-->
            <!--android:layout_marginBottom="6dp"-->
            <!--android:textColor="@color/ColorPrimary"-->
            <!--android:layout_gravity="center"-->
            <!--android:textSize="18sp"-->
            <!--android:gravity="center_vertical|center_horizontal"-->
            <!--android:textStyle="bold"-->
            <!--android:typeface="monospace"/>-->
        <View
            android:layout_width="0dp"
            android:layout_height="fill_parent"
            android:layout_weight="1"
            />
        <Button

            android:layout_width="wrap_content"

            android:padding="16dp"
            android:layout_height="wrap_content"
            android:background="@drawable/category_icon"
            android:drawablePadding="12dp"
            android:gravity="center"
            android:textColor="#FFFFFF"
            android:id="@+id/categoryBtn"
            android:paddingTop="15sp"

            ></Button>
        <View
            android:layout_width="0dp"
            android:layout_height="fill_parent"
            android:layout_weight="0.5"
            />

        <Button

            android:layout_width="wrap_content"

            android:layout_height="wrap_content"
            android:padding="16dp"
            android:background="@drawable/trending_icon"

            android:drawablePadding="12dp"
            android:gravity="center"
            android:textColor="#FFFFFF"
            android:id="@+id/home_btn_2"
            android:paddingTop="15sp"
            ></Button>
        <View
            android:layout_width="0dp"
            android:layout_height="fill_parent"
            android:layout_weight="0.5"
            />
        <Button

            android:layout_width="wrap_content"

            android:layout_height="wrap_content"
            android:padding="16dp"
            android:background="@drawable/explore_icon"
            android:textColor="#FFFFFF"
            android:id="@+id/discover_btn"

            android:paddingTop="15sp"
            ></Button>
        <View
            android:layout_width="0dp"
            android:layout_height="fill_parent"
            android:layout_weight="1"
            />
    </LinearLayout>
</RelativeLayout>
<!-- Nav drawer -->
<include layout="@layout/navdrawer" />
<!--<android.support.design.widget.NavigationView-->
    <!--android:id="@+id/navigation_drawer"-->
    <!--android:layout_width="wrap_content"-->
    <!--android:layout_height="match_parent"-->
    <!--android:layout_gravity="start"-->
    <!--app:menu="@menu/menu_navigation_drawer"/>-->

而我的navdrawer.xml是

<?xml version="1.0" encoding="utf-8"?>
<!--
   Copyright 2015 Google Inc. All rights reserved.
   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at
      http://www.apache.org/licenses/LICENSE-2.0
   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
-->
<!-- This layout is added to most layouts throughout the app using include directives in Activities'
     XML layouts. Google Account and Navigation Item lists are populated through BaseActivity code.
     -->
<windo.com.wind_o.views.ScrimInsetsScrollView
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/navdrawer"
    android:layout_width="@dimen/navdrawer_width"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:background="@color/navdrawer_background"
    app:appInsetForeground="#4000">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">

        <FrameLayout
            android:id="@+id/chosen_account_view"
            android:layout_width="match_parent"
            android:layout_height="@dimen/navdrawer_chosen_account_height"
            >

            <ImageView
                android:id="@+id/profile_cover_image_placeholder"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:paddingTop="@dimen/navdrawer_logo_vertical_padding"
                android:paddingBottom="@dimen/navdrawer_logo_vertical_padding"
                android:paddingRight="@dimen/navdrawer_logo_padding_right"
                android:scaleType="fitEnd"
                android:background="?colorPrimary"
                android:src="@drawable/io_logo"
                android:contentDescription="@string/navview_header_default_image_content_description" />

            <ImageView
                android:id="@+id/profile_cover_image"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:scaleType="centerCrop"
                android:background="?colorPrimary"
                android:visibility="gone"/>

            <RelativeLayout
                android:id="@+id/chosen_account_content_view"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:paddingLeft="@dimen/keyline_1"
                android:paddingRight="@dimen/keyline_1"
                android:paddingTop="@dimen/keyline_1">



                <windo.com.wind_o.views.BezelImageView
                    android:id="@+id/profile_image"
                    android:layout_width="@dimen/navdrawer_profile_image_size"
                    android:layout_height="@dimen/navdrawer_profile_image_size"
                    android:src="@drawable/person_image_empty"
                    android:scaleType="centerCrop"
                    app:maskDrawable="@drawable/circle_mask"
                    />

                <ImageView
                    android:id="@+id/expand_account_box_indicator"
                    android:layout_height="wrap_content"
                    android:layout_width="wrap_content"
                    android:visibility="gone"
                    android:layout_marginStart="@dimen/navview_start_padding"
                    android:layout_marginLeft="@dimen/navview_start_padding"
                    android:paddingBottom="@dimen/navview_header_bottom_padding"
                    android:layout_alignParentRight="true"
                    android:layout_alignParentEnd="true"
                    android:layout_alignParentBottom="true"
                    android:scaleType="center"
                    android:src="@drawable/dotted" />

                <TextView
                    android:id="@+id/profile_email_text"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_alignStart="@id/profile_image"
                    android:layout_alignLeft="@id/profile_image"
                    android:layout_toStartOf="@id/expand_account_box_indicator"
                    android:layout_toLeftOf="@id/expand_account_box_indicator"
                    android:layout_alignParentBottom="true"
                    android:paddingBottom="@dimen/navview_header_bottom_padding"
                    android:textSize="@dimen/text_size_medium"
                    android:textColor="@color/body_text_2_inverse"
                    android:maxLines="1"
                    android:singleLine="true"
                    android:ellipsize="end" />

                <TextView
                    android:id="@+id/profile_name_text"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_above="@id/profile_email_text"
                    android:layout_alignStart="@id/profile_image"
                    android:layout_alignLeft="@id/profile_image"
                    android:layout_toStartOf="@id/expand_account_box_indicator"
                    android:layout_toLeftOf="@id/expand_account_box_indicator"
                    android:textSize="@dimen/text_size_large"
                    android:textColor="@color/body_text_1_inverse"
                    android:maxLines="1"
                    android:singleLine="true"
                    android:ellipsize="end" />

            </RelativeLayout>

        </FrameLayout>

        <FrameLayout android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <!-- Account items -->
            <LinearLayout
                android:id="@+id/account_list"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="@dimen/navview_account_list_top_padding"
                android:orientation="vertical"
                android:visibility="invisible" />

            <!-- Drawer items -->
            <LinearLayout
                android:id="@+id/navdrawer_items_list"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="@dimen/navview_menu_item_top_bottom_padding"
                android:layout_marginBottom="@dimen/navview_menu_item_top_bottom_padding"
                android:orientation="vertical" />
        </FrameLayout>
    </LinearLayout>
</windo.com.wind_o.views.ScrimInsetsScrollView>

在api23上運行該程序可以正常工作,並且顯示所有內容。 但是,當我在帶有api16的模擬器上運行程序時,HomeActivity會引發錯誤

  java.lang.RuntimeException: Unable to start activity ComponentInfo{windo.com.wind_o/windo.com.wind_o.HomeScreen}: android.view.InflateException: Binary XML file line #68: Error inflating class windo.com.wind_o.views.BezelImageView
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
    at android.app.ActivityThread.access$600(ActivityThread.java:130)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:137)
    at android.app.ActivityThread.main(ActivityThread.java:4745)
    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:786)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
    at dalvik.system.NativeStart.main(Native Method)
    Caused by: android.view.InflateException: Binary XML file line #68: Error inflating class windo.com.wind_o.views.BezelImageView
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:698)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
    at android.view.LayoutInflater.parseInclude(LayoutInflater.java:830)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:736)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
    at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:257)
    at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:109)
    at windo.com.wind_o.WindoBaseActivity.setContentView(WindoBaseActivity.java:609)
    at windo.com.wind_o.HomeScreen.onCreate(HomeScreen.java:32)
    at android.app.Activity.performCreate(Activity.java:5008)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084) 
    at android.app.ActivityThread.access$600(ActivityThread.java:130) 
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195) 
    at android.os.Handler.dispatchMessage(Handler.java:99) 
    at android.os.Looper.loop(Looper.java:137) 
    at android.app.ActivityThread.main(ActivityThread.java:4745) 
    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:786) 
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553) 
    at dalvik.system.NativeStart.main(Native Method) 
    Caused by: java.lang.ClassNotFoundException: windo.com.wind_o.views.BezelImageView
    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
    at android.view.LayoutInflater.createView(LayoutInflater.java:552)
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:687)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:746) 
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:749) 
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:749) 
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:749) 
    at android.view.LayoutInflater.parseInclude(LayoutInflater.java:830) 
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:736) 
    at android.view.LayoutInflater.inflate(LayoutInflater.java:489) 
    at android.view.LayoutInflater.inflate(LayoutInflater.java:396) 
    at android.view.LayoutInflater.inflate(LayoutInflater.java:352) 
    at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:257) 
    at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:109) 
    at windo.com.wind_o.WindoBaseActivity.setContentView(WindoBaseActivity.java:609) 
    at windo.com.wind_o.HomeScreen.onCreate(HomeScreen.java:32) 
    at android.app.Activity.performCreate(Activity.java:5008) 
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079) 
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023) 
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084) 
    at android.app.ActivityThread.access$600(ActivityThread.java:130) 
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195) 
    at android.os.Handler.dispatchMessage(Handler.java:99) 
    at android.os.Looper.loop(Looper.java:137) 
    at android.app.ActivityThread.main(ActivityThread.java:4745) 
    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:786) 
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553) 
    at dalvik.system.NativeStart.main(Native Method) 

顯示膨脹異常的第68行是navdrawer.xml中的BezelImageView自定義視圖

過去2天都在處理它,但無法弄清楚為什么它可以在api 23中工作而不能在api 16中工作?

編輯:BezelImageView的代碼

package windo.com.wind_o.views;

/**
 * Borrowed from google iosched
 */

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.ColorMatrix;
import android.graphics.ColorMatrixColorFilter;
import android.graphics.Paint;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffXfermode;
import android.graphics.Rect;
import android.graphics.RectF;
import android.graphics.drawable.Drawable;
import android.support.v4.view.ViewCompat;
import android.util.AttributeSet;
import android.widget.ImageView;


import windo.com.wind_o.R;


/**
 * An {@link android.widget.ImageView} that draws its contents inside a mask and draws a border
 * drawable on top. This is useful for applying a beveled look to image contents, but is also
 * flexible enough for use with other desired aesthetics.
 */
public class BezelImageView extends ImageView {
    private Paint mBlackPaint;
    private Paint mMaskedPaint;

    private Rect mBounds;
    private RectF mBoundsF;

    private Drawable mBorderDrawable;
    private Drawable mMaskDrawable;

    private ColorMatrixColorFilter mDesaturateColorFilter;
    private boolean mDesaturateOnPress = false;

    private boolean mCacheValid = false;
    private Bitmap mCacheBitmap;
    private int mCachedWidth;
    private int mCachedHeight;

    public BezelImageView(Context context) {
        this(context, null);
    }

    public BezelImageView(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public BezelImageView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);

        // Attribute initialization.
        final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.BezelImageView,
                defStyle, 0);

        mMaskDrawable = a.getDrawable(R.styleable.BezelImageView_maskDrawable);
        if (mMaskDrawable != null) {
            mMaskDrawable.setCallback(this);
        }

        mBorderDrawable = a.getDrawable(R.styleable.BezelImageView_borderDrawable);
        if (mBorderDrawable != null) {
            mBorderDrawable.setCallback(this);
        }

        mDesaturateOnPress = a.getBoolean(R.styleable.BezelImageView_desaturateOnPress,
                mDesaturateOnPress);

        a.recycle();

        // Other initialization.
        mBlackPaint = new Paint();
        mBlackPaint.setColor(0xff000000);

        mMaskedPaint = new Paint();
        mMaskedPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));

        // Always want a cache allocated.
        mCacheBitmap = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888);

        if (mDesaturateOnPress) {
            // Create a desaturate color filter for pressed state.
            ColorMatrix cm = new ColorMatrix();
            cm.setSaturation(0);
            mDesaturateColorFilter = new ColorMatrixColorFilter(cm);
        }
    }

    @Override
    protected boolean setFrame(int l, int t, int r, int b) {
        final boolean changed = super.setFrame(l, t, r, b);
        mBounds = new Rect(0, 0, r - l, b - t);
        mBoundsF = new RectF(mBounds);

        if (mBorderDrawable != null) {
            mBorderDrawable.setBounds(mBounds);
        }
        if (mMaskDrawable != null) {
            mMaskDrawable.setBounds(mBounds);
        }

        if (changed) {
            mCacheValid = false;
        }

        return changed;
    }

    @Override
    protected void onDraw(Canvas canvas) {
        if (mBounds == null) {
            return;
        }

        int width = mBounds.width();
        int height = mBounds.height();

        if (width == 0 || height == 0) {
            return;
        }

        if (!mCacheValid || width != mCachedWidth || height != mCachedHeight) {
            // Need to redraw the cache.
            if (width == mCachedWidth && height == mCachedHeight) {
                // Have a correct-sized bitmap cache already allocated. Just erase it.
                mCacheBitmap.eraseColor(0);
            } else {
                // Allocate a new bitmap with the correct dimensions.
                mCacheBitmap.recycle();
                //noinspection AndroidLintDrawAllocation
                mCacheBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
                mCachedWidth = width;
                mCachedHeight = height;
            }

            Canvas cacheCanvas = new Canvas(mCacheBitmap);
            if (mMaskDrawable != null) {
                int sc = cacheCanvas.save();
                mMaskDrawable.draw(cacheCanvas);
                mMaskedPaint.setColorFilter((mDesaturateOnPress && isPressed())
                        ? mDesaturateColorFilter : null);
                cacheCanvas.saveLayer(mBoundsF, mMaskedPaint,
                        Canvas.HAS_ALPHA_LAYER_SAVE_FLAG | Canvas.FULL_COLOR_LAYER_SAVE_FLAG);
                super.onDraw(cacheCanvas);
                cacheCanvas.restoreToCount(sc);
            } else if (mDesaturateOnPress && isPressed()) {
                int sc = cacheCanvas.save();
                cacheCanvas.drawRect(0, 0, mCachedWidth, mCachedHeight, mBlackPaint);
                mMaskedPaint.setColorFilter(mDesaturateColorFilter);
                cacheCanvas.saveLayer(mBoundsF, mMaskedPaint,
                        Canvas.HAS_ALPHA_LAYER_SAVE_FLAG | Canvas.FULL_COLOR_LAYER_SAVE_FLAG);
                super.onDraw(cacheCanvas);
                cacheCanvas.restoreToCount(sc);
            } else {
                super.onDraw(cacheCanvas);
            }

            if (mBorderDrawable != null) {
                mBorderDrawable.draw(cacheCanvas);
            }
        }

        // Draw from cache.
        canvas.drawBitmap(mCacheBitmap, mBounds.left, mBounds.top, null);
    }

    @Override
    protected void drawableStateChanged() {
        super.drawableStateChanged();
        if (mBorderDrawable != null && mBorderDrawable.isStateful()) {
            mBorderDrawable.setState(getDrawableState());
        }
        if (mMaskDrawable != null && mMaskDrawable.isStateful()) {
            mMaskDrawable.setState(getDrawableState());
        }
        if (isDuplicateParentStateEnabled()) {
            ViewCompat.postInvalidateOnAnimation(this);
        }
    }

    @Override
    public void invalidateDrawable(Drawable who) {
        if (who == mBorderDrawable || who == mMaskDrawable) {
            invalidate();
        } else {
            super.invalidateDrawable(who);
        }
    }

    @Override
    protected boolean verifyDrawable(Drawable who) {
        return who == mBorderDrawable || who == mMaskDrawable || super.verifyDrawable(who);
    }
}

所以我終於掌握了這個問題。 錯誤是使視圖膨脹,因為該應用程序找不到Class BezelImageView 我的應用程序中有另一個自定義視圖,它也引發了相同的錯誤。

該類存在,但應用無法找到它。 我解壓縮了我的apk文件,發現有2個dex文件: classes.dexclasses2.dexCustomeView都在classes2.dex文件中。

經過更多檢查后,問題出在android 5以下,該應用無法從classes2.dex加載類。 由於新的Runtime Environment ART,由於默認情況下Android L從所有dex文件中加載類,因此我的應用在Android L上及以上運行良好。

要使類從所有文件加載,我必須做以下事情

  1. 在我的build.gradle中添加multidex庫為

    編譯'com.android.support:multidex:1.0.0'

  2. 在我的應用程序類中重寫attachBaseContext

    protected void attachBaseContext(Context base) { super.attachBaseContext(base); MultiDex.install(this); }

現在,可以在android L下的應用程序中正確找到dex文件中的所有類。

如果不擴展應用程序類,則可以在AndroidManifest.xml中添加以下行

...
<application
...
android:name="android.support.multidex.MultiDexApplication"/>
...

可以在docs上找到上述步驟

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM