Android 6中的滚动条触摸区域 [英] Scrollbar touch area in Android 6

查看:131
本文介绍了Android 6中的滚动条触摸区域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我观察到Android 6.0棉花糖中的新行为.滚动条的触摸区域比滚动条宽.在以下屏幕截图中可见.滚动条具有20 dp(绿色区域),触摸区域可能约为48 dp(蓝色和绿色区域).我只想在滚动条上方设置触摸区域:

I observe new behaviour in Android 6.0 Marshmallow. The touching area of scrollbar is widther than the scrollbar. It is visible on following screenshot. Scrollbar has 20 dp (green area) and touching area is probably 48 dp (blue and green area). I would like to have the touch area above the scrollbar only:

我使用以下内容:

<resources xmlns:android="http://schemas.android.com/apk/res/android">

    <style name="MyTheme.Dark" parent="android:Theme.Black">
        <item name="android:fastScrollStyle">@style/Widget.FastScroll</item>
        <item name="android:scrollbarThumbVertical">@drawable/dark_scrollbar_thumb</item>
        <item name="android:scrollbarTrackVertical">@drawable/dark_scrollbar_track</item>
        <item name="android:scrollbarSize">4dp</item>
        <item name="android:fastScrollThumbDrawable">@drawable/dark_scrollbar_fast_thumb</item>
        <item name="android:fastScrollTrackDrawable">@drawable/dark_scrollbar_fast_track</item>
    </style>

    <style name="Widget.FastScroll" parent="android:Widget.Material.FastScroll">
    </style>

</resources>

dark_scrollbar_fast_thumb.xml:

dark_scrollbar_fast_thumb.xml:

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >

    <item>
        <shape>
            <size
                android:height="30dp"
                android:width="20dp" />

            <solid android:color="@android:color/transparent" />
        </shape>
    </item>

    <item android:left="8dp" android:right="8dp">
        <shape>
            <size
                android:height="30dp"
                android:width="4dp" />

            <solid android:color="@color/dark_secondary" />
        </shape>
    </item>

</layer-list>

dark_scrollbar_fast_track.xml:

dark_scrollbar_fast_track.xml:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >

    <size android:width="@dimen/1dp" />
    <solid android:color="@color/dark_scrollbar_track" />

</shape>

dark_scrollbar_fast_thumb.xml:

dark_scrollbar_fast_thumb.xml:

<item>
    <shape>
        <size
            android:height="30dp"
            android:width="20dp" />

        <solid android:color="@android:color/transparent" />
    </shape>
</item>

<item android:left="8dp" android:right="8dp">
    <shape>
        <size
            android:height="30dp"
            android:width="4dp" />

        <solid android:color="@color/dark_secondary" />
    </shape>
</item>

dark_scrollbar_fast_track.xml:

dark_scrollbar_fast_track.xml:

<size android:width="@dimen/1dp" />
<solid android:color="@color/dark_scrollbar_track" />

快速滚动条始终可见,并且我在列表视图中使用以下样式:

Fast scrollbar is always visible and I use following style in listviews:

<item name="android:scrollbarStyle">outsideInset</item>

但是结果看起来更像是outsideOverlay.我只能在棉花糖设备上观察到此问题.

But the result looks more like outsideOverlay. I can observe this issue only on Marshmallow devices.

我想找到引起它的属性并将其从48dp更改为20dp.你能帮我吗?

I would like to find the attribute that causes it and change it from 48dp to 20dp. Would you please help me?

推荐答案

我遇到了相同的问题,最终使用了变通方法.

I encountered the same issue and ended up using a workaround.

诀窍是在用户不滚动时(或停止滚动后1秒)禁用快速滚动,并在用户再次开始滚动时重新激活快速滚动. 为此,您需要像这样实现 OnScrollListener 并将侦听器设置为listview:

The trick is to disable the fast scroll when the user is not scrolling (or 1 sec after he stopped scrolling), and reactivate it when he starts scrolling again. In order to do so, youn need to implement OnScrollListener like this and set the listener to the listview:

private int mCurrentState = 0;

@Override
public void onScrollStateChanged(AbsListView absListView, int state) {

    if (state == SCROLL_STATE_IDLE && mCurrentState != state && mListview.isFastScrollEnabled()){

        mListview.postDelayed(new Runnable() {
            @Override
            public void run() {
                mListview.setFastScrollEnabled(false);
            }
        },1000);

    }

    mCurrentState = state;
}

@Override
public void onScroll(AbsListView absListView, int i, int i1, int i2) {

    if (mCurrentState == SCROLL_STATE_TOUCH_SCROLL) {


        if (!mListview.isFastScrollEnabled())
            mListview.setFastScrollEnabled(true);
    }
}

希望这可能对您有帮助

这篇关于Android 6中的滚动条触摸区域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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