我在其中一个布局中使用了HorizontalScrollView
,并且通过覆盖相应的xml属性来替换滚动条轨道和拇指,以便轨道代表HorizontalScrollView
内的视图的缩略图以及拇指指示当前位置。Android - 在HorizontalScrollView中使滚动条可点击
到目前为止,这工作正常,我可以在视图内滚动。但是,我不能使用滚动条,即滚动的滚动条和滚动条,我只能通过整个视图顶部的滚动条进行滚动。在滚动条顶部的每次点击/扔掉简单解释就像在HorizontalScrollView
其他地方的点击/扔掉。换句话说,我不能拖动拇指从而改变位置,也不能通过单击滚动条轨道上的某个位置来跳转到某个位置。
这里是我的布局:
<HorizontalScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:scrollbarFadeDuration="0"
android:scrollbarThumbHorizontal="@drawable/highlight_box"
android:scrollbarTrackHorizontal="@drawable/tumbnail_chain" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="horizontal" >
...couple of FrameLayouts
</LinearLayout>
</HorizontalScrollView>
可惜我找不到任何解决这个问题还没有
编辑:
我只是发现了滚动条是不应该这个工作Android的方式,请参阅 here
有没有人有一个想法,我如何能够实现上面解释的所需行为?没有代码需要,只是建议!
EDIT 2(解决方法):
为了谁感兴趣的我的解决方案中的:我把一个透明的虚拟视图上相同尺寸的滚动条的顶部,设置OnTouchListener
这一观点。在收听者的onTouch
方法我然后计算触摸事件的相对位置只要在轨迹栏关注,并且然后经由scrollTo
方法HorizontalScrollView
内跳转到相同的相对位置:
public boolean onTouch (View v, MotionEvent event) {
int x = Math.round((event.getX()/mScrollbarWidth) * mScrollViewWidth);
mScrollView.scrollTo(x, 0);
return true;
}
其中mScrollBarWidth是滚动条的宽度(基本上是屏幕宽度),mScrollViewWidth是HorizontalScrollView
的总宽度。由于此方法在触摸虚拟视图期间被连续调用,因此您不仅可以跳到您触摸的位置,还可以在滚动条上拖动拇指。
我不认为touch事件被拦截,因为通过fling滚动确实按照需要工作,只是滚动条不能用于滚动,正如人们可能从非android应用程序期望的那样。也许我没有足够清楚地阐明我的问题。 – Schnodahipfe 2012-02-13 12:44:37
我编辑的问题可能会有问题,现在希望它更连贯一些 – Schnodahipfe 2012-02-13 13:01:14