Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/228.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/119.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/spring-boot/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
锁定水平滚动视图-Android_Android_Locking_Horizontal Scrolling - Fatal编程技术网

锁定水平滚动视图-Android

锁定水平滚动视图-Android,android,locking,horizontal-scrolling,Android,Locking,Horizontal Scrolling,我正在编写一个应用程序,它如下所示: 您可以看到顶部是SeekBar,下面是HorizontalScrolView中的几个按钮。我想使用SeekBar来滚动按钮,现在可以了,但是我不能关闭滚动视图的默认方式(绘图屏幕)。我在论坛上找到了类似的话题: 但问题是,这种方式锁定了整个ScrollView,而我不能通过seekBar和默认方式使用它-也许我做错了什么(我在链接中也这么做了,即使在mScrollable参数中有TRUE,这也不是麦汁)。第二个问题是我的按钮(有fill_parent h

我正在编写一个应用程序,它如下所示:

您可以看到顶部是SeekBar,下面是HorizontalScrolView中的几个按钮。我想使用SeekBar来滚动按钮,现在可以了,但是我不能关闭滚动视图的默认方式(绘图屏幕)。我在论坛上找到了类似的话题:

但问题是,这种方式锁定了整个ScrollView,而我不能通过seekBar和默认方式使用它-也许我做错了什么(我在链接中也这么做了,即使在mScrollable参数中有TRUE,这也不是麦汁)。第二个问题是我的按钮(有fill_parent height参数)非常小

问:有什么好方法可以用默认方式锁定滚动视图,并使用SeekBar来实现这一点

我的代码(默认水平滚动视图):

主要活动:

 <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#0A0A0A"
    android:orientation="vertical" >

    <SeekBar
        android:id="@+id/seekBar"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" />

    <HorizontalScrollView
        android:id="@+id/hsv"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:scrollbars="none" >

        <RelativeLayout
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"
            android:orientation="horizontal" >

           <!-- BUTTONS CODE - NOT IMPORTANT --> 

        </RelativeLayout>
    </HorizontalScrollView>

</LinearLayout>

有什么好方法可以用默认方式锁定滚动视图并使用 SeekBar怎么做

编辑:

解决方案似乎要简单得多,覆盖
HorizontalScrollView
类并通过视图传递触摸事件:

public class MyHScroll extends HorizontalScrollView {

    // the constructors

    @Override
    public boolean onTouchEvent(MotionEvent ev) {
        return false;
    }

}
在布局中使用此类,而不是默认的
HorizontallScrollView

<com.your.package.MyHScroll
    android:id="@+id/hsv"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:scrollbars="none" >

    <RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:orientation="horizontal" >

       <!-- BUTTONS CODE - NOT IMPORTANT --> 

    </RelativeLayout>
</com.your.package.MyHScroll>
然后在
onCreate
方法中为覆盖小部件添加一个
OnTouchListener
,以进一步阻止触摸事件:

findViewById(R.id.overlay).setOnTouchListener(new OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            return true;
        }
    });
第二个问题是我的按钮(具有填充高度) 参数)非常小


请参阅上面的布局文件。

这可以解决我的问题,但会产生另一个问题-现在我无法使用按钮;/我尝试使用onDragListener而不是onTouchLister,但它使我的应用程序崩溃;/有什么想法吗?我想检查X和Y,检查它应该是哪个按钮,然后执行我的方法,但我觉得这不太好think@CookieMonssster是的,没想太多。我已经编辑了我的答案,看看是否有效。
 <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#0A0A0A"
    android:orientation="vertical" >

    <SeekBar
        android:id="@+id/seekBar"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" />
    <FrameLayout android:layout_width="wrap_content"
        android:layout_height="fill_parent">

    <HorizontalScrollView
        android:id="@+id/hsv"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:scrollbars="none" >

        <RelativeLayout
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"
            android:orientation="horizontal" >

           <!-- BUTTONS CODE - NOT IMPORTANT --> 

        </RelativeLayout>
    </HorizontalScrollView>

    <View android:id="@+id/overlay" android:layout_width="fill_parent"
        android:layout_height="fill_parent" />

    </FrameLayout

</LinearLayout>
findViewById(R.id.overlay).setOnTouchListener(new OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            return true;
        }
    });