我正在尝试在我的应用程序中使用Faria 的 KenBurnsView库。
KenBurnsView 是 ImageView 的一些扩展,具有很好的动画效果。您可能已经在 Foursquare 应用程序的图像中看到了这种效果。
对于实际图片,视图使用 XML 定义的“android:src”属性。但我想通过 Java 代码在运行时设置图像资源。我尝试过 setImageResource、setBackgroundResource、set".."drawabale 和许多其他方法。但无论如何,我的图像设置命令总是让我的应用程序在运行时崩溃。
我已经在网上搜索了几个小时,以寻找关于 KenBurnsView 的任何讨论痕迹,但没有任何运气。
我的问题是:
如何在运行时设置 KenBurnsView 的图像属性?
编辑 :
这是堆栈跟踪:
06-16 01:26:43.062: E/AndroidRuntime(16712): FATAL EXCEPTION: main
06-16 01:26:43.062: E/AndroidRuntime(16712): Process: com.flaviofaria.kenburnsview.sample, PID: 16712
06-16 01:26:43.062: E/AndroidRuntime(16712): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.flaviofaria.kenburnsview.sample/com.flaviofaria.kenburnsview.sample.SingleImageActivity}: java.lang.NullPointerException
06-16 01:26:43.062: E/AndroidRuntime(16712): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2184)
06-16 01:26:43.062: E/AndroidRuntime(16712): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233)
06-16 01:26:43.062: E/AndroidRuntime(16712): at android.app.ActivityThread.access$800(ActivityThread.java:135)
06-16 01:26:43.062: E/AndroidRuntime(16712): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
06-16 01:26:43.062: E/AndroidRuntime(16712): at android.os.Handler.dispatchMessage(Handler.java:102)
06-16 01:26:43.062: E/AndroidRuntime(16712): at android.os.Looper.loop(Looper.java:136)
06-16 01:26:43.062: E/AndroidRuntime(16712): at android.app.ActivityThread.main(ActivityThread.java:5001)
06-16 01:26:43.062: E/AndroidRuntime(16712): at java.lang.reflect.Method.invokeNative(Native Method)
06-16 01:26:43.062: E/AndroidRuntime(16712): at java.lang.reflect.Method.invoke(Method.java:515)
06-16 01:26:43.062: E/AndroidRuntime(16712): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
06-16 01:26:43.062: E/AndroidRuntime(16712): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
06-16 01:26:43.062: E/AndroidRuntime(16712): at dalvik.system.NativeStart.main(Native Method)
06-16 01:26:43.062: E/AndroidRuntime(16712): Caused by: java.lang.NullPointerException
06-16 01:26:43.062: E/AndroidRuntime(16712): at com.flaviofaria.kenburnsview.MathUtils.getRectRatio(MathUtils.java:44)
06-16 01:26:43.062: E/AndroidRuntime(16712): at com.flaviofaria.kenburnsview.RandomTransitionGenerator.generateRandomRect(RandomTransitionGenerator.java:93)
06-16 01:26:43.062: E/AndroidRuntime(16712): at com.flaviofaria.kenburnsview.RandomTransitionGenerator.generateNextTransition(RandomTransitionGenerator.java:64)
06-16 01:26:43.062: E/AndroidRuntime(16712): at com.flaviofaria.kenburnsview.KenBurnsView.startNewTransition(KenBurnsView.java:207)
06-16 01:26:43.062: E/AndroidRuntime(16712): at com.flaviofaria.kenburnsview.KenBurnsView.handleImageChange(KenBurnsView.java:280)
06-16 01:26:43.062: E/AndroidRuntime(16712): at com.flaviofaria.kenburnsview.KenBurnsView.setImageResource(KenBurnsView.java:126)
06-16 01:26:43.062: E/AndroidRuntime(16712): at com.flaviofaria.kenburnsview.sample.SingleImageActivity.onCreate(SingleImageActivity.java:36)
06-16 01:26:43.062: E/AndroidRuntime(16712): at android.app.Activity.performCreate(Activity.java:5231)
06-16 01:26:43.062: E/AndroidRuntime(16712): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
06-16 01:26:43.062: E/AndroidRuntime(16712): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2148)
06-16 01:26:43.062: E/AndroidRuntime(16712): ... 11 more