自定义视图的布局帮助
我正在自定义视图中玩 2D 绘图。到目前为止,我已经绘制了我想要的内容(来自数组的点数据),但我希望绘图能够缩放并能够将其扩展到屏幕之外(例如每个屏幕宽度 1 秒的数据)。我用于绘图的方法依赖于 getHeight
和 getWidth
来设置屏幕中信息的边界。我使用屏幕宽度将 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 永远不会被调用。
I'm playing around with 2D drawing within a custom view. So far I've got it drawing what I want(Point data from an array) but I want the drawing to scale and be able to extend it beyond the screen(such that 1 second of data per screen width). The method I'm using for drawing relies on getHeight
and getWidth
to set the bounds of the information in the screen. I'm using the screens width to extend the canvas in onDraw
to several screen widths in size(depending on the time of the data).
I've been unable to find a way of drawing that will allow me to scroll horizontally, and support a zoom like function... is there an easy way of doing this? ScrollView doesn't do Horizontally, and when I go beyond the screen it just get's cut off. My layout so far is
<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>
But when I put this in, the onDraw of my view never get's called.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这可能会解决您的问题。
尽管我怀疑它是否具有缩放功能,但您应该能够使用它来实现您所要求的其余功能。
编辑:
层次结构如下:
This may solve your problem.
Although I doubt that it has a zoom function, you should be able to implement the rest of what you're asking for using this.
EDIT:
The hierarchy would go as follows: