android-从图像视图获取可绘制

android-从图像视图获取可绘制,第1张

概述当我执行this文档ImageView.getDrawable中描述的剪辑可绘制示例时,始终返回null.有人可以帮助我吗?在MainActivity.java中onCreate@OverrideprotectedvoidonCreate(BundlesavedInstanceState){super.onCreate(savedInstanceState);setContentView

当我执行this文档ImageVIEw.getDrawable中描述的剪辑可绘制示例时,始终返回null.有人可以帮助我吗?

在MainActivity.java中onCreate

@OverrIDe    protected voID onCreate(Bundle savedInstanceState)    {        super.onCreate(savedInstanceState);        setContentVIEw(R.layout.activity_main);        ImageVIEw imagevIEw = (ImageVIEw) findVIEwByID(R.ID.image);        ClipDrawable drawable = (ClipDrawable) imagevIEw.getDrawable();        drawable.setLevel(drawable.getLevel() + 1000); //line number 21    }

Logcat

 02-04 12:16:31.156: E/AndroIDRuntime(4611): FATAL EXCEPTION: main02-04 12:16:31.156: E/AndroIDRuntime(4611): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.test/com.example.test.MainActivity}: java.lang.NullPointerException02-04 12:16:31.156: E/AndroIDRuntime(4611):      at androID.app.ActivityThread.performlaunchActivity(ActivityThread.java:1647)02-04 12:16:31.156: E/AndroIDRuntime(4611):      at androID.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)02-04 12:16:31.156: E/AndroIDRuntime(4611):      at androID.app.ActivityThread.access00(ActivityThread.java:117)02-04 12:16:31.156: E/AndroIDRuntime(4611):      at androID.app.ActivityThread$H.handleMessage(ActivityThread.java:931)02-04 12:16:31.156: E/AndroIDRuntime(4611):      at androID.os.Handler.dispatchMessage(Handler.java:99)02-04 12:16:31.156: E/AndroIDRuntime(4611):      at androID.os.Looper.loop(Looper.java:123)02-04 12:16:31.156: E/AndroIDRuntime(4611):      at androID.app.ActivityThread.main(ActivityThread.java:3683)02-04 12:16:31.156: E/AndroIDRuntime(4611):      at java.lang.reflect.Method.invokeNative(Native Method)02-04 12:16:31.156: E/AndroIDRuntime(4611):      at java.lang.reflect.Method.invoke(Method.java:507)02-04 12:16:31.156: E/AndroIDRuntime(4611):      at com.androID.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)02-04 12:16:31.156: E/AndroIDRuntime(4611):      at com.androID.internal.os.ZygoteInit.main(ZygoteInit.java:597)02-04 12:16:31.156: E/AndroIDRuntime(4611):      at dalvik.system.NativeStart.main(Native Method)02-04 12:16:31.156: E/AndroIDRuntime(4611): Caused by: java.lang.NullPointerException02-04 12:16:31.156: E/AndroIDRuntime(4611):      at com.example.test.MainActivity.onCreate(MainActivity.java:21)02-04 12:16:31.156: E/AndroIDRuntime(4611):      at androID.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)02-04 12:16:31.156: E/AndroIDRuntime(4611):      at androID.app.ActivityThread.performlaunchActivity(ActivityThread.java:1611)02-04 12:16:31.156: E/AndroIDRuntime(4611):      ... 11 more

解决方法:

您必须重写onwindowsFocusChanged()

 @OverrIDe public voID onWindowFocusChanged(boolean hasWindowFocus) {    super.onWindowFocusChanged(hasWindowFocus);   ClipDrawable drawable = (ClipDrawable) imagevIEw.getBackground();    drawable.setLevel(drawable.getLevel() + 1000); //line number 21 }

尝试获取其值(可绘制图像)时,imageVIEw尚未正确显示.
onwindowsFocusChanged()将通知用户该视图已被加载,这是您可以获取其数据的时候了.

总结

以上是内存溢出为你收集整理的android-从图像视图获取可绘制全部内容,希望文章能够帮你解决android-从图像视图获取可绘制所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1211125.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-04
下一篇 2022-06-04

发表评论

登录后才能评论

评论列表(0条)

保存