【问题标题】:capture whole scrollview, bigger than the UI捕获整个滚动视图,比 UI 大
【发布时间】:2013-11-15 11:32:54
【问题描述】:

我需要捕获一个超出可见 UI 的滚动视图,我使用了以下代码:

ScrollView view2 = (ScrollView)findViewById(R.id.scrollCapture);
    view2.setDrawingCacheEnabled(true);
    view2.buildDrawingCache();
    Bitmap bm = view2.getDrawingCache();

但它只捕获显示的屏幕,而不是整个布局。

有没有什么方法可以捕捉整个布局,甚至没有显示?

非常感谢。

【问题讨论】:

    标签: android scrollview screenshot capture


    【解决方案1】:

    不要使用滚动视图,而是使用直接子项(只允许一个直接子项)。例如,如果您的 xml 文件是

    <ScrollView
     android:id="@+id/scrollCapture">
      <LinearLayout
        android:id="@+id/scrollCaptureChild">
      </LinearyLayout>
    </ScrollView>
    

    LinearyLayout view3 = (LinearyLayout)findViewById(R.id.scrollCaptureChild);
    view3.setDrawingCacheEnabled(true);
    view3.buildDrawingCache();
    Bitmap bm = view3.getDrawingCache();
    

    【讨论】:

    • 感谢您的关注,但我的活动看起来像那样,无论如何似乎无法捕获 UI 未显示的屏幕部分 :(,我尝试了很多东西,但是没办法做到这一点:(
    • 只截取屏幕可见部分
    • stackoverflow.com/questions/9791714/…尝试标记为已接受答案的解决方案
    【解决方案2】:
    Bitmap bitmap = Bitmap.createBitmap(scrollView.getChildAt(0).getWidth(), scrollView.getChildAt(0).getHeight(), Bitmap.Config.ARGB_8888);
    Canvas c = new Canvas(bitmap);
    scrollView.getChildAt(0).draw(c);
    

    【讨论】:

      猜你喜欢
      • 2014-07-22
      • 1970-01-01
      • 2023-04-11
      • 1970-01-01
      • 1970-01-01
      • 2013-03-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多