首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >SeekBar in a NavigationDrawer

SeekBar in a NavigationDrawer
EN

Stack Overflow用户
提问于 2013-08-23 10:46:15
回答 2查看 3.1K关注 0票数 20

我想在导航抽屉里用一个查找条

基本上,我需要向左和右滑动设置搜索栏,你猜到了,它滑动了导航抽屉.

我想做的是当它聚焦的时候滑动搜索栏,当它不是的时候滑动导航抽屉。

我该怎么做?

以下是设置项时的代码(我还没有设置查找栏)

代码语言:javascript
复制
private View onCritereView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    View mView = inflater.inflate(R.layout.fragment_critere, container, false);
    LinearLayout mLinearLayout = (LinearLayout) mView.findViewById(R.id.critere_linearlayout);

    View mViewElement = inflater.inflate(R.layout.item_critere, null);
    ((TextView)mViewElement.findViewById(R.id.critere_title)).setText("Prix Maximum");

    mLinearLayout.addView(mViewElement);

    return mView;
}

下面是带有查找条的item_critere.xml

代码语言:javascript
复制
<?xml version="1.0" encoding="utf-8"?>
<TableLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/critere_item"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:stretchColumns="*">

    <TableRow
            android:layout_width="fill_parent"
            android:layout_height="fill_parent">

        <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textAppearance="?android:attr/textAppearanceMedium"
                android:text="Large Text"
                android:id="@+id/critere_title"
                android:layout_gravity="left|center_vertical"
                android:layout_column="0"/>

        <SeekBar
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:id="@+id/critere_qualifier"
                android:layout_column="1"
                android:layout_span="4"/>
    </TableRow>

    <TableRow
            android:layout_width="fill_parent"
            android:layout_height="fill_parent">

        <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textAppearance="?android:attr/textAppearanceSmall"
                android:text="Medium Text"
                android:id="@+id/critere_value"
                android:layout_span="4"/>
    </TableRow>

</TableLayout>

(预先谢谢:)

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2013-08-23 11:23:41

只需添加一个onTouchListener。当您触摸查找栏(action_down)上的屏幕时,不允许父节点拦截事件。

代码语言:javascript
复制
seekbar.setOnTouchListener(new ListView.OnTouchListener() 
{
    @Override
    public boolean onTouch(View v, MotionEvent event) 
    {
        int action = event.getAction();
        switch (action) 
        {
        case MotionEvent.ACTION_DOWN:
            // Disallow Drawer to intercept touch events.
            v.getParent().requestDisallowInterceptTouchEvent(true);
            break;

        case MotionEvent.ACTION_UP:
            // Allow Drawer to intercept touch events.
            v.getParent().requestDisallowInterceptTouchEvent(false);
            break;
        }

        // Handle seekbar touch events.
        v.onTouchEvent(event);
        return true;
    }
});
票数 37
EN

Stack Overflow用户

发布于 2019-07-12 14:27:01

使用DrawerLayout.setDrawerLockMode

而不是ViewParent.requestDisallowInterceptTouchEvent

在@dumazy应答中,requestDisallowInterceptTouchEvent解决了这个问题,但它也创建了另一个问题。

当您在导航抽屉上滚动时,如果您触摸SeekBar,OnSeekBarChangeListener将触发。因此,滚动事件将打破和寻找栏的进展将开始改变,通过移动你的手指。

我修改了原来的答案,用DrawerLockMode来解决这个问题。

代码语言:javascript
复制
mSeekBar.setOnTouchListener(new SeekBar.OnTouchListener() {
    @Override
    public boolean onTouch(View v, MotionEvent event) {
        int action = event.getAction();
        switch (action) {

            case MotionEvent.ACTION_DOWN:
                // Disallow Drawer to intercept touch events.
                // v.getParent().requestDisallowInterceptTouchEvent(true);
                mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_OPEN);
                break;

            case MotionEvent.ACTION_UP:
            case MotionEvent.ACTION_CANCEL:
                // Allow Drawer to intercept touch events.
                // v.getParent().requestDisallowInterceptTouchEvent(false);
                mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNDEFINED);
                break;
        }

        // Handle SeekBar touch events.
        v.onTouchEvent(event);
        return true;
    }
});
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/18400910

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档