其他分享
首页 > 其他分享> > android – 隐藏ScrollView棒在某些设备上给出空指针异常

android – 隐藏ScrollView棒在某些设备上给出空指针异常

作者:互联网

我尝试设置ScrollView的android:scrollbars =“none”属性,但问题是在输入信息时键盘已启动然后如果您尝试滚动则不会滚动直到布局结束.

我使用下面的代码行隐藏滚动条,< ScrollView>标签在布局中

android:scrollbarThumbVertical="@null"

它在三星s4设备上运行得很好,但在LG它崩溃时有以下异常 –

FATAL EXCEPTION: main 
java.lang.NullPointerException
at android.widget.ScrollBarDrawable.setAlpha(ScrollBarDrawable.java: 221)
at android.view.View.onDrawScrollBars(View.java: 11306)
at android.view.View.draw(View.java: 13567)
at android.widget.FrameLayout.draw(FrameLayout.java: 467)
at android.widget.ScrollView.draw(ScrollView.java: 1752)
at android.view.View.getDisplayList(View.java: 12512)
at android.view.View.getDisplayList(View.java: 12556)
at android.view.View.draw(View.java: 13285)
at android.view.ViewGroup.drawChild(ViewGroup.java: 2931)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java: 2801)
at android.view.View.draw(View.java: 13564)
at android.view.View.getDisplayList(View.java: 12512)
at android.view.View.getDisplayList(View.java: 12556)
at android.view.View.draw(View.java: 13285)
at android.view.ViewGroup.drawChild(ViewGroup.java: 2931)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java: 2801)
at android.view.View.draw(View.java: 13564)
at android.widget.FrameLayout.draw(FrameLayout.java: 467)
at android.view.View.getDisplayList(View.java: 12512)
at android.view.View.getDisplayList(View.java: 12556)
at android.view.View.draw(View.java: 13285)
at android.view.ViewGroup.drawChild(ViewGroup.java: 2931)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java: 2801)
at android.view.View.getDisplayList(View.java: 12510)
at android.view.View.getDisplayList(View.java: 12556)
at android.view.View.draw(View.java: 13285)
at android.view.ViewGroup.drawChild(ViewGroup.java: 2931)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java: 2801)
at android.view.View.draw(View.java: 13564)
at android.widget.FrameLayout.draw(FrameLayout.java: 467)
at com.android.internal.policy.impl.PhoneWindow$DecorView.draw(PhoneWindow.java: 2473)
at android.view.HardwareRenderer$GlRenderer.draw(HardwareRenderer.java: 1206)
at android.view.ViewRootImpl.draw(ViewRootImpl.java: 2169)
at android.view.ViewRootImpl.performDraw(ViewRootImpl.java: 2041)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java: 1849)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java: 1009)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java: 4256)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java: 725)
at android.view.Choreographer.doCallbacks(Choreographer.java: 555)
at android.view.Choreographer.doFrame(Choreographer.java: 525)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java: 711)
at android.os.Handler.handleCallback(Handler.java: 615)
at android.os.Handler.dispatchMessage(Handler.java: 92)
at android.os.Looper.loop(Looper.java: 137)
at android.app.ActivityThread.main(ActivityThread.java: 4917)
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: 790)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java: 557)
at dalvik.system.NativeStart.main(Native Method)

是什么原因它在某些设备上运行而不是全部?

唯一正确的选择是通过以下方式设置它 – 如下所示 –

yourScrollView.setVerticalScrollBarEnabled(false);

解决方法:

@null值导致NullPointerException.您可以使用透明drawable:

android:scrollbarThumbVertical="@android:color/transparent"

标签:android,android-scrollview
来源: https://codeday.me/bug/20190829/1760266.html