Android 两个方向上滚动视图内元素的固定位置
我正在我的Android应用程序中构建一个视图,它可以水平和垂直滚动。因此,我用一个水平滚动视图包围了我的视图,在这个水平滚动视图中,我有另一个滚动视图(垂直滚动视图) 在滚动视图的顶部有一个时间轴(图中为红色)。滚动垂直滚动视图时,时间线应该是静态的。它应该保持在顶部。因此,此时间线在顶部始终可见 在这些滚动视图的左侧,我有五个按钮(图中的颜色不同)。这些按钮应使用垂直滚动视图而不是水平滚动视图滚动,这意味着这些按钮应始终在左侧可见 滚动视图中的白色区域将双向滚动 我已经设法使时间线(图中的红色)保持在顶部,并且仅使用水平滚动视图滚动,但我无法确定应该将五个按钮放在何处以确保它们也保持在顶部,并且仅使用垂直滚动视图滚动 这是我现在的布局,时间线保持在顶部Android 两个方向上滚动视图内元素的固定位置,android,xml,layout,scrollview,horizontal-scrolling,Android,Xml,Layout,Scrollview,Horizontal Scrolling,我正在我的Android应用程序中构建一个视图,它可以水平和垂直滚动。因此,我用一个水平滚动视图包围了我的视图,在这个水平滚动视图中,我有另一个滚动视图(垂直滚动视图) 在滚动视图的顶部有一个时间轴(图中为红色)。滚动垂直滚动视图时,时间线应该是静态的。它应该保持在顶部。因此,此时间线在顶部始终可见 在这些滚动视图的左侧,我有五个按钮(图中的颜色不同)。这些按钮应使用垂直滚动视图而不是水平滚动视图滚动,这意味着这些按钮应始终在左侧可见 滚动视图中的白色区域将双向滚动 我已经设法使时间线(图中的红
<!-- Horizontal scroll view -->
<HorizontalScrollView android:id="@+id/schedule_concerts_scroll_view"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:fadingEdge="none"
android:scrollbars="none"
android:layout_below="@+id/schedule_day_pager_layout">
<!-- Scroll container for horizontal scroll view -->
<RelativeLayout android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:id="@+id/schedule_layout">
<!-- The timeline (red in the illustration) Should only scroll horizontal and stay at top -->
<RelativeLayout android:id="@+id/schedule_timeline"
android:layout_width="wrap_content"
android:layout_height="23dp"
android:layout_marginBottom="0dp"
android:layout_alignParentTop="true" />
<!-- Vertical scroll view -->
<ScrollView android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:fadingEdge="none"
android:scrollbars="none"
android:layout_below="@+id/schedule_timeline">
<!-- Scroll container for vertical scroll view -->
<RelativeLayout android:layout_width="wrap_content"
android:layout_height="wrap_content">
<!-- The content here should be scrolling both ways -->
</RelativeLayout>
</ScrollView>
</RelativeLayout>
</HorizontalScrollView>
这就是我所指的例子。这应该有助于解释我的布局应该如何结束
有人知道我如何在两个方向都有固定位置的视图的情况下实现两个方向的滚动吗?我发现很容易将左侧的按钮从两个滚动视图中移出,并在滚动垂直滚动视图时收听
onScrollChanged
,然后相应地滚动按钮。因此,当调用onScrollChanged()
时,我将按钮放在滚动视图中,并在此滚动视图上调用onScroll()
有关如何扩展ScrollView以实现
onScrollChanged()
的详细说明,请参见。我发现,将左侧的按钮从两个滚动视图中移出并侦听onScrollChanged
是很容易的,每当滚动垂直滚动视图时,都会相应地滚动按钮。因此,当调用onScrollChanged()
时,我将按钮放在滚动视图中,并在此滚动视图上调用onScroll()
有关如何扩展ScrollView以实现onScrollChanged()
的详细说明,请参阅