2011-08-10 188 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