滚动即使搜索栏感动 [英] Scroll even if the seekbar is touched

查看:240
本文介绍了滚动即使搜索栏感动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是搜索栏,在一个ScroolView在NavigationDrawer一个的LinearLayout

I am using a seekbar in a linearlayout in a ScroolView in a NavigationDrawer

NavigationDrawer>滚动型>的LinearLayout>搜索栏+其他的东西。

NavigationDrawer > ScrollView > LinearLayout > SeekBar + other stuff

在我接触到搜索栏我无法向上和向下滚动,我想。

When I touch the seekbar I am unable to scroll up and down and I'd like to.

下面我的功能,它让我的搜索栏滑动而不是滑动抽屉式导航

Here my function which allow me to slide the seekbar instead of slide the navigation drawer

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);

    int i;
    for (i = 0; i < mTitles.length; i++) {
        View mViewElement = inflater.inflate(R.layout.item_critere, null);
        ((TextView) mViewElement.findViewById(R.id.critere_title)).setText(mTitles[i]);
        SeekBar mSeekBar = (SeekBar) mViewElement.findViewById(R.id.critere_qualifier);
        mSeekBar.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;
            }
        });
        mLinearLayout.addView(mViewElement);
    }
    return mView;
}

现在我需要的是:

如果你触摸搜索栏,如果你滑hozizontaly使用搜索栏。

If you touch the seekbar and if you slide hozizontaly use seekbar.

否则,如果你触摸搜索栏和如果滑动verticaly使用滚动视图

else if you touch the seekbar and if you slide verticaly use scrollview

我怎么能这样做?

在此先感谢:)

推荐答案

下面是一个工作VerticalSeekBar实现:

Here is a working VerticalSeekBar implementation:

package android.widget;

import android.content.Context;
import android.graphics.Canvas;
import android.util.AttributeSet;
import android.view.MotionEvent;

public class VerticalSeekBar extends SeekBar {

    public VerticalSeekBar(Context context) {
        super(context);
    }

    public VerticalSeekBar(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }

    public VerticalSeekBar(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    protected void onSizeChanged(int w, int h, int oldw, int oldh) {
        super.onSizeChanged(h, w, oldh, oldw);
    }

    @Override
    protected synchronized void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(heightMeasureSpec, widthMeasureSpec);
        setMeasuredDimension(getMeasuredHeight(), getMeasuredWidth());
    }

    protected void onDraw(Canvas c) {
        c.rotate(-90);
        c.translate(-getHeight(), 0);

        super.onDraw(c);
    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        if (!isEnabled()) {
            return false;
        }

        switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
            case MotionEvent.ACTION_MOVE:
            case MotionEvent.ACTION_UP:
                setProgress(getMax() - (int) (getMax() * event.getY() / getHeight()));
                onSizeChanged(getWidth(), getHeight(), 0, 0);
                break;

            case MotionEvent.ACTION_CANCEL:
                break;
        }
        return true;
    }
}

要实现它,在你的项目中创建一个新的类,选择正确的软件包:

To implement it, create a new class in your project, choosing the right package:

有,粘贴code和保存。现在用它在你的XML布局:

There, paste the code and save it. Now use it in your XML layout:

<android.widget.VerticalSeekBar
  android:id="@+id/seekBar1"
  android:layout_width="wrap_content"
  android:layout_height="200dp"
  />

这篇关于滚动即使搜索栏感动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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