【问题标题】:How to take a screenshot of vertical and horizontal layout in Android如何在Android中截取垂直和水平布局的屏幕截图
【发布时间】:2014-03-09 00:11:52
【问题描述】:

我有一个显示数学练习表/矩阵的应用程序。这张桌子可能真的很大,所以我使用垂直和水平布局。我需要截取整个布局的截图,但它只保存可见屏幕的截图。我该怎么办?

这是我的布局

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/myScrollView"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" >

    <HorizontalScrollView
        android:id="@+id/myHorizontalScrollView"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent" >

        <TableLayout
            android:id="@+id/myTableLayout"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:stretchColumns="1" />

    </HorizontalScrollView>
</ScrollView>

这是我截取屏幕截图的方式,但只是可见屏幕,而不是整个布局

View v1 = getWindow().getDecorView().getRootView();
v1.setDrawingCacheEnabled(true);
Bitmap myBitmap = v1.getDrawingCache();        
saveBitmap(myBitmap); // saves to storage

编辑:使用此代码,我可以截取非常宽的表格,但如果它也太高,应用程序崩溃并显示: View too large to fit into drawing cache, needs 2030336 bytes, only 1536000 available 。现在我不知道问题是我用来捕获视图的方法,还是根本不可能捕获具有例如 20 行和列的表。为什么位图这么大?

TableLayout tableView = (TableLayout) findViewById(R.id.myTableLayout);
tableView.setDrawingCacheEnabled(true);
tableView.layout(0, 0, tableView.getWidth(), tableView.getHeight());
tableView.buildDrawingCache(true);
tableView.setBackgroundColor(Color.WHITE);
Bitmap bitmap = Bitmap.createBitmap(tableView.getDrawingCache());
tableView.setDrawingCacheEnabled(false);

【问题讨论】:

  • 不,它不是重复的。他正在截取抵消活动的截图。我需要截取活动活动但大表的屏幕截图。
  • 您是否尝试过其他方法?它看起来会起作用
  • 刚刚看到您的编辑,尝试拆分屏幕截图,使其分成几部分,然后将其拼接在一起。
  • 也许你可以看看这个:stackoverflow.com/a/10651384/2121682

标签: android screenshot horizontalscrollview


【解决方案1】:

这个呢? https://stackoverflow.com/a/16501007/2121682你的问题是一样的,但方法不同。我希望它有效。 可能您已经看过这个,但以防万一。

【讨论】:

  • 我之前在 stackoverflow 上找到了所有这些答案,但没有一个有效。我也试过这个,但它没有意义。为什么它绘制画布然后返回位图?它不起作用,在我尝试截屏后它只是显示空白页。
猜你喜欢
  • 1970-01-01
  • 2016-03-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-06-01
  • 2017-10-09
相关资源
最近更新 更多