如何在Scrollview中实现画布视图

时间:2015-05-12 14:03:16

标签: android android-canvas android-scrollview

我正在开发绘图类型的应用程序,我想在Scrollview中实现画布视图。但在Scrollview中实现时,canvas视图不起作用。是否有任何一般程序来实现这一目标?

1 个答案:

答案 0 :(得分:-1)

要做到这一点,您只需要重新绘制自己的自定义视图类。我的意思是这样的:

$services_custom_default = array('supports' => array( 'title', 'editor','thumbnail', 'revisions' ),'menu_icon' => get_stylesheet_directory_uri().'/include/cpt/images/portfolio.png',);
$services = new Super_Custom_Post_Type( 'services', 'Service', 'Services', $services_custom_default );
$services->add_meta_box( array('id' => 'services_settings','context' => 'normal','fields' => array('icon_type' => array( 'type' => 'select', 'options' => array('font-awesome' => 'Font-Awesome','glyphicons' => 'Glyphicons', 'image' => 'Image' ), 'data-zp_desc' => __( 'Select icons to use. Font-Awesome, Glyphicons or an Image.','start') ),'icon_class' => array( 'type' => 'text','data-zp_desc' => __( 'Add icon classes. For font-awesome classes, please refer to this link <a href="http://fontawesome.io/icons/">page</a>. For Glyphicons, refer to this <a href="http://getbootstrap.com/components/">page</a> ','start') ),'icon_link' => array( 'type' => 'text', 'data-zp_desc' => __( 'Service item link','start') ),'icon_target' => array( 'type' => 'select', 'options' => array('_blank' => '_blank','_self' => '_self', '_parent' => '_parent' ), 'data-zp_desc' => __( 'Target','start') ),)
) );

然后使用它,所有你需要它的代码:

public class CustomView extends View {
    // Constructors and other stuff
    public void onDraw(Canvas canvas) {
        // All your drawing here

        // Note: If you want an infinite thread (like SurfaceView) put
        // invalidate();
        // at the end of the function
        // Otherwise to trigger the onDraw, manually call
        // yourCustomView.invalidate();
        // every time you want to re-draw
    }
}