有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java Android片段视图,带有垂直滚动条和左右滑动手势检测

我正在实现一个简单的笑话应用程序,其功能是左右滑动以查看下一个或上一个笑话。一个笑话可能很长,因此我需要文本视图上的滚动条。但是,看起来ontouch侦听器和滚动条相互干扰,滚动后滑动不起作用。有什么想法吗

<RelativeLayout xmlns:安卓="http://schemas.安卓.com/apk/res/安卓"
                xmlns:tools="http://schemas.安卓.com/tools"
                安卓:layout_width="match_parent"
                安卓:layout_height="match_parent"
                安卓:background="#FFF"
                tools:context="com.bontututu.bontu.JokeFragment">

    <ScrollView
        安卓:id="@+id/textAreaScroller"
        安卓:layout_width="wrap_content"
        安卓:layout_height="wrap_content"
        安卓:layout_x="0px"
        安卓:layout_y="25px"
        安卓:scrollbars="vertical">

        <TextView
            安卓:id="@+id/txtJoke"
            style="@style/jokeText"
            安卓:layout_width="match_parent"
            安卓:layout_height="match_parent"
            安卓:layout_toLeftOf="@+id/txtSwipeLeft"
            安卓:layout_toRightOf="@+id/txtSwipeRight"
            安卓:gravity="center"
            安卓:text=""/>
    </ScrollView>

    <TextView
        安卓:id="@+id/txtSwipeRight"
        style="@style/swipeIndicatorStyle"
        安卓:layout_width="40dp"
        安卓:layout_height="match_parent"
        安卓:layout_alignParentLeft="true"
        安卓:layout_centerInParent="true"
        安卓:gravity="center"
        安卓:text="☛"
        安卓:visibility="gone"/>

    <TextView
        安卓:id="@+id/txtSwipeLeft"
        style="@style/swipeIndicatorStyle"
        安卓:layout_width="40dp"
        安卓:layout_height="match_parent"
        安卓:layout_alignParentRight="true"
        安卓:layout_centerInParent="true"
        安卓:gravity="center"
        安卓:text="☚"
        安卓:visibility="gone"/>

</RelativeLayout>

下面是片段代码的一部分

 @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
    {
        final View view = inflater.inflate(R.layout.fragment_joke, container, false);
        _textViewJoke = (TextView) view.findViewById(R.id.txtJoke);
        _textViewLeftSwipeIndicator = (TextView) view.findViewById(R.id.txtSwipeLeft);
        _textViewRightSwipeIndicator = (TextView) view.findViewById(R.id.txtSwipeRight);
        _mainScrollView = (ScrollView) view.findViewById(R.id.textAreaScroller);
        getJokes();
        displayCurrentJoke();
        view.setOnTouchListener(new OnSwipeTouchListener(getActivity())
        {
            @Override
            public void onSwipeRight()
            {
                _mainScrollView.requestDisallowInterceptTouchEvent(true);
                if (_jokes != null)
                {
                    _currentJokeIndex--;
                    displayCurrentJoke();
                }
            }

            @Override
            public void onSwipeLeft()
            {
                _mainScrollView.requestDisallowInterceptTouchEvent(true);
                if (_jokes != null)
                {
                    _currentJokeIndex++;
                    displayCurrentJoke();
                }
            }

            @Override
            public void onSwipeTop()
            {
                _mainScrollView.requestDisallowInterceptTouchEvent(false);
            }

            @Override
            public void onSwipeBottom()
            {
                _mainScrollView.requestDisallowInterceptTouchEvent(false);
            }

            @Override
            public boolean onTouch(View v, MotionEvent event)
            {
                return gestureDetector.onTouchEvent(event);
            }
        });
        return view;
    }
}

共 (0) 个答案