【发布时间】: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