android - 为 Canvas 应用水平 ScrollView

标签 android

您好,我正在 Canvas 上显示一些线条。现在我想为这些线条应用水平 ScrollView 。请给我一些(代码)建议。提前致谢

最佳答案

你必须在你的类中定义 ScrollView ,

    ScrollView sc=new ScrollView(this);
sc.measure(400, 10);
        int width = sc.getMeasuredWidth();
        int height = sc.getMeasuredHeight();
        int left = 100;
        int top = 100;
           sc.layout(0, top, left + width, top + height);

然后你必须为此设置布局参数。

然后你可以像这样在 Canvas 上绘制它:

sc.draw(canvas); //canvas is your canvas name on which you are drawing

已编辑

我认为对您来说非常简单的另一种方法是在您的主布局中使用一个 ScrollView 并将您的 View 包含在其中。所以它不需要在其中绘制滚动。

关于android - 为 Canvas 应用水平 ScrollView ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4870818/

相关文章:

android - 在 android 4.3 上写入/系统/等的权限

android - Android 中的 Handlers 和 Runnables 有什么用?

java - 具有异步任务的 fragment 中的 ListView

android - 使图像上的某种颜色透明

android - node-gcm 只发送消息给 1 个设备?

android - adb 重启未完成

android - 向下滚动到达 RecyclerView 顶部时如何扩展 AppBarLayout

android - 如何给安卓应用添加样式

android - 获取 ListView 以在各种数组之间切换以进行显示

Android:如何以编程方式访问 AVD 管理器中显示的设备序列号(API 版本 8)