Java 安卓:如何制作可滚动画布?
我正在写一个应用程序。它的一个方面是在图像上绘制线条。以下是我一直使用的实践代码: 公共类DrawView扩展视图{ 油漆=新油漆()Java 安卓:如何制作可滚动画布?,java,android,canvas,drawable,Java,Android,Canvas,Drawable,我正在写一个应用程序。它的一个方面是在图像上绘制线条。以下是我一直使用的实践代码: 公共类DrawView扩展视图{ 油漆=新油漆() 我希望画布相当大,因此我需要人们能够在两个方向(左/右和上/下)滚动。我如何实现这一点?我不熟悉Canvas类,因此非常感谢您的帮助。如果您想在画布上绘制自定义高度和宽度,您必须调用setContentView(android.view.view yourView,android.view.Viewgroup.LayoutParam YourLayourLayo
我希望画布相当大,因此我需要人们能够在两个方向(左/右和上/下)滚动。我如何实现这一点?我不熟悉Canvas类,因此非常感谢您的帮助。如果您想在画布上绘制自定义高度和宽度,您必须调用setContentView(android.view.view yourView,android.view.Viewgroup.LayoutParam YourLayourLayout)。因为默认情况下setContentView(view-view)方法使用全宽和全高。因此,您必须使用其重载方法和两个参数以及所需参数。有关详细信息,请参阅文档。不要仅使用LayoutParams()构造函数来创建它的对象。通过像android.view.ViewGroup.LayoutParams这样编写它的完整路径来使用它。因为在android SDK中还有一些同名的其他类
MyView customView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
customView = new MyView(getApplicationContext());
android.view.ViewGroup.LayoutParams lp = new android.view.ViewGroup.LayoutParams(100,200);//100 is width and 200 is height
setContentView(customView, lp);
customView.setOnClickListener(this);
}`
MyView customView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
customView = new MyView(getApplicationContext());
android.view.ViewGroup.LayoutParams lp = new android.view.ViewGroup.LayoutParams(100,200);//100 is width and 200 is height
setContentView(customView, lp);
customView.setOnClickListener(this);
}`