在外部库组件使用情况下,误差夸大类



i创建一个简单的小部件,该小部件使用PIE/DONUT图表(Circle Progress Bar)提供相同的数据。我想使用一些外部组件,所以我选择了:

com.github.lzyzsd.circleprogress.ArcProgress

我将ArcProgress组件放在我的widget.xml上,我可以在预览选项卡中清楚地看到它。没有汇编,构建或任何其他错误。当我运行应用程序并将小部件放在主屏幕上时,我将面临一个例外:

W/AppWidgetHostView: updateAppWidget couldn't find any view, using error view
      android.view.InflateException: Binary XML file line #37: Binary XML file line #37: Error inflating class com.github.lzyzsd.circleprogress.ArcProgress
      Caused by: android.view.InflateException: Binary XML file line #37: Error inflating class com.github.lzyzsd.circleprogress.ArcProgress
      Caused by: java.lang.ClassNotFoundException: Didn't find class "com.github.lzyzsd.circleprogress.ArcProgress" on path: DexPathList[[zip file "/data/app/com.sec.android.app.launcher-2/base.apk", zip file "/data/app/com.sec.android.app.launcher-2/base.apk"],nativeLibraryDirectories=[/data/app/com.sec.android.app.launcher-2/lib/arm64, /system/lib64, /vendor/lib64]]
          at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
          at java.lang.ClassLoader.loadClass(ClassLoader.java:380)
          at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
          at android.view.LayoutInflater.createView(LayoutInflater.java:616)
          at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:794)
          at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:734)
          at android.view.LayoutInflater.rInflate(LayoutInflater.java:865)
          at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:828)
          at android.view.LayoutInflater.rInflate(LayoutInflater.java:873)
          at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:828)
          at android.view.LayoutInflater.inflate(LayoutInflater.java:525)
          at android.view.LayoutInflater.inflate(LayoutInflater.java:427)
          at android.widget.RemoteViews.inflateView(RemoteViews.java:3844)
          at android.widget.RemoteViews.apply(RemoteViews.java:3808)
          at android.appwidget.AppWidgetHostView.applyRemoteViews(AppWidgetHostView.java:456)
          at android.appwidget.AppWidgetHostView.updateAppWidget(AppWidgetHostView.java:385)
          at com.android.launcher3.home.LauncherAppWidgetHostView.updateAppWidget(LauncherAppWidgetHostView.java:161)
          at android.appwidget.AppWidgetHost.updateAppWidgetView(AppWidgetHost.java:418)
          at android.appwidget.AppWidgetHost$UpdateHandler.handleMessage(AppWidgetHost.java:136)
          at android.os.Handler.dispatchMessage(Handler.java:102)
          at android.os.Looper.loop(Looper.java:154)
          at android.app.ActivityThread.main(ActivityThread.java:6776)
          at java.lang.reflect.Method.invoke(Native Method)
          at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1520)
          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1410)

我认为Gradle有一些问题,因为我的第一次尝试是:

az.plainpie.PieView

结果是相同的(但是classNotfound是" az.plainpie.pieview")。

我的widget.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              xmlns:custom="http://schemas.android.com/tools"
              xmlns:app="http://schemas.android.com/apk/res-auto"
              android:orientation="horizontal"
              android:layout_width="match_parent"
              android:layout_height="match_parent"
              android:padding="@dimen/widget_margin"
              android:background="#AA000000">
              <!--xmlns:plainpie="http://schemas.android.com/apk/res-auto"-->

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/countryView"
        android:visibility="visible">
<!--        <az.plainpie.PieView
            android:id="@+id/globalValue"
            android:layout_width="100dp"
            android:layout_height="100dp"
            plainpie:inner_pie_padding="10"
            plainpie:percentage="75"
            plainpie:percentage_size="35"
            plainpie:inner_text_visibility="true"/>  -->
        <com.github.lzyzsd.circleprogress.ArcProgress
            android:id="@+id/arc_progress"
            android:layout_width="100dp"
            android:layout_height="100dp"
            app:arc_bottom_text_size="10sp"
            app:arc_progress="55"
            app:arc_bottom_text="VALUE"/>
        <TextView
            android:id="@+id/countryText"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:gravity="center"
            android:text="temp"
            android:textSize="@dimen/text_size_big"
            android:textStyle="bold"
            android:textColor="@color/colorWhite"/>
    </LinearLayout>
</LinearLayout>

项目gradle:

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.2.2'
        classpath 'me.tatarka:gradle-retrolambda:3.6.1'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}
allprojects {
    repositories {
        jcenter()
        maven { url "https://jitpack.io" }
    }
}
task clean(type: Delete) {
    delete rootProject.buildDir
}

模块gradle:

apply plugin: 'com.android.application'
apply plugin: 'me.tatarka.retrolambda'
android {
    compileSdkVersion 25
    buildToolsVersion "25.0.2"
    defaultConfig {
        applicationId 'pl.test.simplewidget'
        minSdkVersion 15
        targetSdkVersion 25
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    productFlavors {
    }
}
dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.google.code.gson:gson:2.8.0'
    compile 'com.squareup.retrofit2:retrofit:2.3.0'
    compile 'com.squareup.retrofit2:converter-gson:2.3.0'
    compile 'com.squareup.okhttp3:logging-interceptor:3.8.0' 
    compile group: 'joda-time', name: 'joda-time', version: '2.9.9'
    compile 'com.github.zurche:plain-pie:v0.2.1' //pie chart library zurche/plain-pie
    compile 'com.github.lzyzsd:circleprogress:1.2.1' // circle progress bar
    compile 'com.jakewharton:butterknife:8.6.0'
    annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'
    compile 'com.android.support:appcompat-v7:25.3.1'
    testCompile 'junit:junit:4.12'
}

我尝试了干净的项目,卸载应用程序,使用其他手机。我的Android Studio没有选中"离线工作",并已检查了建议的"默认Gradle包装器"。我搜索了解决方案,但它们都没有解决我的问题。你能看到怎么了吗?

不幸的是,您无法在应用程序窗口小部件中使用这些自定义视图,如文档所述:

如果您熟悉布局,则创建应用程序小部件布局很简单。但是,您必须意识到应用程序小部件布局是基于的在远程视图上,不支持各种布局或查看窗口小部件

在Android上阅读有关相关问题的阅读:具有自定义视图的AppWidget不起作用

相关内容

最新更新