不能做出微调的滚动条总是可见的(安卓) [英] Can't make spinner's scrollbar always visible (Android)

查看:199
本文介绍了不能做出微调的滚动条总是可见的(安卓)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样一个问题 - 我想使微调的滚动条始终可见。 但微调的功能

  setScrollbarFadingEnabled(假);
 

会导致崩溃了NullExceptionPointer绘制图形用户界面中。

XML标签解决不了这个问题太 - 似乎微调不理会他们。

也许有另一种方式来转移?例如,使用自定义滚动的?如果是的话,我该怎么办呢?

谢谢您的回答, 梅德。

正如我一直在问,这里是简单的项目LogCat中的错误信息,在它只是一个微调:

  AndroidRuntime(2252):致命异常:主要
AndroidRuntime(2252):显示java.lang.NullPointerException
AndroidRuntime(2252):在android.view.View.onDrawScrollBars(View.java:5836)
AndroidRuntime(2252):在android.view.View.draw(View.java:6799)
AndroidRuntime(2252):在android.view.ViewGroup.drawChild(ViewGroup.java:1640)
AndroidRuntime(2252):在android.view.ViewGroup.dispatchDraw(ViewGroup.java:1367)
AndroidRuntime(2252):在android.view.ViewGroup.drawChild(ViewGroup.java:1638)
AndroidRuntime(2252):在android.view.ViewGroup.dispatchDraw(ViewGroup.java:1367)
AndroidRuntime(2252):在android.view.View.draw(View.java:6796)
AndroidRuntime(2252):在android.widget.FrameLayout.draw(FrameLayout.java:352)
AndroidRuntime(2252):在android.view.ViewGroup.drawChild(ViewGroup.java:1640)
AndroidRuntime(2252):在android.view.ViewGroup.dispatchDraw(ViewGroup.java:1367)
AndroidRuntime(2252):在android.view.ViewGroup.drawChild(ViewGroup.java:1638)
AndroidRuntime(2252):在android.view.ViewGroup.dispatchDraw(ViewGroup.java:1367)
AndroidRuntime(2252):在android.view.View.draw(View.java:6796)
AndroidRuntime(2252):在android.widget.FrameLayout.draw(FrameLayout.java:352)
AndroidRuntime(2252):在com.android.internal.policy.impl.PhoneWindow $ DecorView.draw(PhoneWindow.java:2078)
AndroidRuntime(2252):在android.view.ViewRoot.draw(ViewRoot.java:1433)
AndroidRuntime(2252):在android.view.ViewRoot.performTraversals(ViewRoot.java:1175)
AndroidRuntime(2252):在android.view.ViewRoot.handleMessage(ViewRoot.java:1753)
AndroidRuntime(2252):在android.os.Handler.dispatchMessage(Handler.java:99)
AndroidRuntime(2252):在android.os.Looper.loop(Looper.java:123)
AndroidRuntime(2252):在android.app.ActivityThread.main(ActivityThread.java:4632)
AndroidRuntime(2252):在java.lang.reflect.Method.invokeNative(本机方法)
AndroidRuntime(2252):在java.lang.reflect.Method.invoke(Method.java:521)
AndroidRuntime(2252):在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:871)
AndroidRuntime(2252):在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:629)
AndroidRuntime(2252):在dalvik.system.NativeStart.main(本机方法)
 

解决方案

微调没有滚动条,因此你越来越NullPointerException异常。

通过微调显示的弹出窗口有滚动条。所以,你需要改变由微调显示ListView控件的属性。但是,ListView控件本身没有被微调暴露的任何公共方法。

即使你通过反射得到ListPopupWindow,另一个问题出现了,那ListPopupWindow的ListView控件之后您单击微调只创建。

但微调的OnClickListener不能注册,演出结束后,设置ListView的属性。

您可以创建自定义微调与performClick覆盖,然后让mPopup反射。并使用 mPopup.getListView()。setScrollbarFadingEnabled(假)

但是,如果你要创建一个自定义的微调,我认为这是比较容易实现整个弹出,以满足您的需要比使用反射。

I have such a problem - I want to make spinner's scrollbar always visible. But for spinner function

setScrollbarFadingEnabled(false);

causes crash with a NullExceptionPointer during drawing the GUI.

XML tags can't solve this problem too - it seems that spinner just ignore them.

Maybe there are another ways to move? For example, using of the custom scrollbar? If yes, how can I do this?

Thanks for your answers, Dmitry.

As I've been asked, here is LogCat error message for simple project with just a spinner in it:

AndroidRuntime(2252): FATAL EXCEPTION: main
AndroidRuntime(2252): java.lang.NullPointerException
AndroidRuntime(2252): at android.view.View.onDrawScrollBars(View.java:5836)
AndroidRuntime(2252): at android.view.View.draw(View.java:6799)
AndroidRuntime(2252): at android.view.ViewGroup.drawChild(ViewGroup.java:1640)
AndroidRuntime(2252): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1367)
AndroidRuntime(2252): at android.view.ViewGroup.drawChild(ViewGroup.java:1638)
AndroidRuntime(2252): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1367)
AndroidRuntime(2252): at android.view.View.draw(View.java:6796)
AndroidRuntime(2252): at android.widget.FrameLayout.draw(FrameLayout.java:352)
AndroidRuntime(2252): at android.view.ViewGroup.drawChild(ViewGroup.java:1640)
AndroidRuntime(2252): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1367)
AndroidRuntime(2252): at android.view.ViewGroup.drawChild(ViewGroup.java:1638)
AndroidRuntime(2252): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1367)
AndroidRuntime(2252): at android.view.View.draw(View.java:6796)
AndroidRuntime(2252): at android.widget.FrameLayout.draw(FrameLayout.java:352)
AndroidRuntime(2252): at com.android.internal.policy.impl.PhoneWindow$DecorView.draw(PhoneWindow.java:2078)
AndroidRuntime(2252): at android.view.ViewRoot.draw(ViewRoot.java:1433)
AndroidRuntime(2252): at android.view.ViewRoot.performTraversals(ViewRoot.java:1175)
AndroidRuntime(2252): at android.view.ViewRoot.handleMessage(ViewRoot.java:1753)
AndroidRuntime(2252): at android.os.Handler.dispatchMessage(Handler.java:99)
AndroidRuntime(2252): at android.os.Looper.loop(Looper.java:123)
AndroidRuntime(2252): at android.app.ActivityThread.main(ActivityThread.java:4632)
AndroidRuntime(2252): at java.lang.reflect.Method.invokeNative(Native Method)
AndroidRuntime(2252): at java.lang.reflect.Method.invoke(Method.java:521)
AndroidRuntime(2252): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:871)
AndroidRuntime(2252): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:629)
AndroidRuntime(2252): at dalvik.system.NativeStart.main(Native Method)

解决方案

Spinner does not have a scrollbar, Hence you are getting NullPointerException.

The popup shown by spinner has a scrollbar. So you need to change the properties of the ListView shown by spinner. But ListView itself is not exposed by Spinner by any public methods.

Even if you get the ListPopupWindow by reflection, a further problem arises, that ListPopupWindow's ListView is only created after you click the Spinner.

But OnClickListener of the Spinner cannot be registered , to set the ListView Properties after the show.

You could create a Custom Spinner with performClick overridden and then get mPopup by reflection. and use mPopup.getListView().setScrollbarFadingEnabled(false)

But If you are going to create a custom Spinner, i believe it is easier to implement the whole popup to suit your needs than using reflection.

这篇关于不能做出微调的滚动条总是可见的(安卓)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆