我创建了一个简单的小部件,使用饼图/圆环图(圆形进度条)显示相同的数据。 我想使用一些外部组件,所以我选择了:
let rec smallest_divisor : int -> int
=fun n -> let i = ref 2 if n mod !i = 0 then i else (i :!i+1; smallest_divisor(n))
我将ArcProgress组件放到我的widget.xml中,我可以在预览选项卡中清楚地看到它。没有编译,构建或任何其他错误。 当我运行应用程序并将小部件放到主屏幕时,我面临一个例外:
com.github.lzyzsd.circleprogress.ArcProgress
我认为gradle存在一些问题,因为我的第一次尝试是:
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)
并且结果相同(但ClassNotFound当然是“az.plainpie.PieView”)。
我的widget.xml:
az.plainpie.PieView
项目gradle:
<?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
}
我尝试过干净的项目,卸载应用程序,使用不同的手机。 我的Android Studio取消选中“离线工作”并检查推荐的“默认gradle包装器”。我搜索了解决方案,但没有一个解决了我的问题。你能看出出了什么问题吗?
答案 0 :(得分:2)
很遗憾,您不能像在the documentation中那样在App小部件中使用这些自定义视图:
上阅读相关问题如果您熟悉Layouts,则创建App Widget布局很简单。但是,您必须知道App Widget布局是基于的 在RemoteViews上,不支持所有类型的布局或视图小部件。