2011-08-10 184 views
0

我在自定義視圖內玩弄2D繪圖。到目前爲止,我已經繪製了我想要的圖形(點陣數據),但我希望繪圖能夠縮放並能夠將其擴展到屏幕之外(例如,每個屏幕寬度1秒的數據)。我用於繪製的方法依賴於getHeightgetWidth來設置屏幕中信息的邊界。我使用屏幕寬度將onDraw中的畫布擴展爲幾個屏幕寬度(取決於數據的時間)。自定義視圖的佈局幫助

我一直無法找到一種繪圖方式,這將允許我水平滾動,並支持像函數一樣的縮放...有沒有一種簡單的方法來做到這一點? ScrollView不會水平移動,當我超越屏幕時,它會被切斷。我的佈局到目前爲止

<HorizontalScrollView 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_weight="1" 
    > 
     <LinearLayout 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:orientation="horizontal" 
     > 
      <view class="com.box.sand.SandGraph$GraphView" 
       android:id="@+id/graph" 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" 
      /> 
     </LinearLayout> 
    </HorizontalScrollView> 

但是,當我把這個,我的觀點的的onDraw永遠不會叫。

回答

0

This may solve your problem

儘管我懷疑它具有縮放功能,但您應該能夠實現您要求使用此功能的其餘部分。

編輯:

層次結構會去如下:

<HorizontalScrollView ... > 
    <LinearLayout android:orientation="horizontal" > 
     <Content goes here /> 
    </LinearLayout> 
</HorizontalScrollView> 
+0

我曾試圖利用這一點,它不會顯示任何內容,我的觀點中的'getHeight'是被包裹在這但我會深入研究這個階級。 – Nicholas

+0

您需要確保您用作單個子項的LinearLayout設置爲android:orientation =「horizo​​ntal」。另外,請確保您爲此視圖的子項使用單個佈局。 – Codeman

+0

那麼我會將我的視圖包裹在Horizo​​ntalScrollView中,然後是LinearLayout中的HSV? – Nicholas