隐藏 ScrollView 棒在某些设备上会出现空指针异常

Hiding ScrollView stick gives null pointer exception on some devices

我尝试设置 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。您可以改用透明的可绘制对象:

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