拍摄整个“截图"可滚动视图 [英] Take whole "Screenshot" of a scrollable View

查看:29
本文介绍了拍摄整个“截图"可滚动视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的 Fragment 布局中,我有一个 ScrollView,里面有一个 LinearLayout

In my Fragment's layout i have a ScrollView with a LinearLayout inside

<ScrollView
    android:id="@+id/scrollview"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" >

    <LinearLayout
        android:id="@+id/container"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical" >

        <!-- Other views -->

    </LinearLayout>
</ScrollView>

所以我需要创建和共享滚动视图的整个内容的图片.我尝试过的所有解决方案都只截取可见区域的屏幕截图,而不是整个滚动视图内容的屏幕截图.我该怎么办?

So i need to create and share a picture of entire content of scrollview. All solutions i've tried take screenshot only of the visible area, and not of entire scrollview content. How can i do?

推荐答案

我希望这对你有用.. source 此处.从技术上讲,这不是屏幕截图代码.但是这段代码将整个布局视图转换为位图

I hope this is work for you.. source here. this is not technically a screenshot code. but this code convert the whole layout view into bitmap

Bitmap bitmap = getBitmapFromView(scrollview, scrollview.getChildAt(0).getHeight(), scrollview.getChildAt(0).getWidth());

//create bitmap from the ScrollView 
private Bitmap getBitmapFromView(View view, int height, int width) {
    Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);
    Drawable bgDrawable = view.getBackground();
    if (bgDrawable != null)
        bgDrawable.draw(canvas);
    else
        canvas.drawColor(Color.WHITE);
    view.draw(canvas);
    return bitmap;
}

这篇关于拍摄整个“截图"可滚动视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆