I also searched for this solution and, in the end, I was able to come up with my own solution, which is actually quite simple.
In my case, I had a LinearLayout
that contained several View
elements, some of which sometimes were not on the screen, vertically below the end of the borders of the screen. I was able to save the View
as a bitmap (see below loadBitmapFromView()
), but had problems when it expanded beyond the bottom of the screen.
My solution was to make part of the LinearLayout
of the LinearLayout
composite.
eg.
It:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/my_linear_layout" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > </LinearLayout>
Became:
Pay attention to using wrap_content
to ensure ScrollView is scaled to the height of your content.
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/scroll" android:layout_width="fill_parent" android:layout_height="wrap_content" > <LinearLayout android:id="@+id/my_linear_layout" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" > </LinearLayout> </ScrollView>
It seemed that in order for me to save the View
as a bitmap, it was possible to manually lay out elements off the screen. I used the following method to save a bitmap. I found this a lot earlier on SO, but I can't find the question to edit it correctly (whoever you are - thanks!).
For the next method, I pass the link to LinearLayout
above ( my_linear_layout
).
public static Bitmap loadBitmapFromView(View view) { Bitmap bitmap = null;
source share