2012-02-05 65 views
0

我在我的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> 

這就是我所說的例證。這應該有助於解釋我的佈局應該如何結束。

Illustration of scroll directions

有誰知道我怎麼能與具有兩個方向的固定位置的看法兩個方向實現滾動?

回答

1

我發現很容易將左側的按鈕移出滾動視圖,並傾聽onScrollChanged以及每當滾動垂直滾動視圖時,然後相應地滾動按鈕。因此,我在調用onScrollChanged()時將按鈕放在滾動視圖中,並在此滾動視圖上調用onScroll()

有關如何延長滾動型有很大的描述來實現onScrollChanged()看,this answer