我有一个列表视图,启用了快速滚动。第一次,快速滚动条不可见。但是,如果我导航到另一个屏幕并回到此状态,那么它就会变得可见。最新的Android操作系统版本会出现此问题。即,4.4 - Kitkat
第一次访问
第二次访问
有关为什么会这样发生的想法吗?
答案 0 :(得分:6)
我有同样的问题。我使用解决方案:
gridView.setFastScrollEnabled(true);
if (Build.VERSION.SDK_INT >= 19) {
gridView.setOnScrollListener(new OnScrollListener() {
private static final int DELAY = 2000;
private AbsListView view;
@Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
if (scrollState != SCROLL_STATE_IDLE) {
view.setFastScrollAlwaysVisible(true);
handler.removeCallbacks(runnable);
}
else {
this.view = view;
handler.postDelayed(runnable, DELAY);
}
}
@Override
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
}
private Handler handler = new Handler();
private Runnable runnable = new Runnable() {
@Override
public void run() {
view.setFastScrollAlwaysVisible(false);
view = null;
}
};
});
}
答案 1 :(得分:0)
对我有用的是延迟setFastScrollEnabled()
的电话。
if (Build.VERSION.SDK_INT >= 19) {
mListView.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
@SuppressWarnings("deprecation")
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
@Override
public void onGlobalLayout() {
mListView.setFastScrollEnabled(true);
if (Build.VERSION.SDK_INT >= 16) {
mListView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
} else {
mListView.getViewTreeObserver().removeGlobalOnLayoutListener(this);
}
}
});
} else {
mListView.setFastScrollEnabled(true);
}
答案 2 :(得分:0)
这是一种解决方法:
public static void setFastScrolledEnabled(final AdapterView<?> adapterView,final boolean enable)
{
final GridView gridView;
final ListView listView;
if(adapterView instanceof GridView)
{
gridView=(GridView)adapterView;
listView=null;
}
else if(adapterView instanceof ListView)
{
listView=(ListView)adapterView;
gridView=null;
}
else throw new UnsupportedOperationException("setFastScrolledEnabled is only available for gridView/listView");
if(Build.VERSION.SDK_INT==VERSION_CODES.KITKAT)
adapterView.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener()
{
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
@Override
public void onGlobalLayout()
{
if(gridView!=null)
gridView.setFastScrollEnabled(enable);
else if(listView!=null)
listView.setFastScrollEnabled(enable);
adapterView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
}
});
else if(gridView!=null)
gridView.setFastScrollEnabled(enable);
else if(listView!=null)
listView.setFastScrollEnabled(enable);
}