Note that there are some explanatory texts on larger screens.

plurals
  1. POTaking a "screenshot" of a specific layout in Android
    text
    copied!<p>I have two main issues which are closely linked. I am looking at these problems from a programmatic point of view.</p> <p><strike> (1) - I wish to take a screenshot of the contents of a SPECIFIC layout, i.e. a <code>ScrollView</code> nested in a <code>LinearLayout</code>.</strike></p> <p>(2) - As the <code>ScrollView</code> has content that spills out of the screen (hence scrolling made possible), how can I ensure that the screenshot includes the elements that are not visible on the screen?</p> <p>This is the current block of code I use. It does the job of taking a screenshot but only for the entire screen. <strike>This is even though <code>R.id.boss</code> is the ID of the <code>ScrollView</code> and not the main <code>LinearLayout</code>.</strike></p> <pre><code>View view = findViewById(R.id.boss); View v = view.getRootView();// this does not seem to make a difference v.setDrawingCacheEnabled(true); v.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED), MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED)); v.layout(0, 0, v.getMeasuredWidth(), v.getMeasuredHeight()); v.buildDrawingCache(true); Bitmap b = Bitmap.createBitmap(u.getDrawingCache()); v.setDrawingCacheEnabled(false); </code></pre> <p>Thanks in advance.</p> <p><strong>EDIT:</strong></p> <p>I've made a few mistakes. I used <code>R.id.boss</code> which is the wrong resource. I am now able to take a screenshot of the scrollview alone, less the out-of-screen parts.</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/boss" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_gravity="top" android:orientation="vertical" &gt; &lt;TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="F" android:textAppearance="?android:attr/textAppearanceMedium" /&gt; &lt;TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Analyze via image URL" android:textAppearance="?android:attr/textAppearanceSmall" /&gt; &lt;LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" &gt; &lt;EditText android:id="@+id/mUrl" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="0.7" android:text="http://" &gt; &lt;requestFocus /&gt; &lt;/EditText&gt; &lt;ImageView android:id="@+id/call" android:layout_width="75dp" android:layout_height="50dp" android:layout_weight="0.3" android:text="ABC" android:src="@drawable/run" /&gt; &lt;/LinearLayout&gt; &lt;TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="ABC" android:textAppearance="?android:attr/textAppearanceSmall" /&gt; &lt;LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" &gt; &lt;EditText android:id="@+id/filepath" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="0.55" /&gt; &lt;ImageView android:id="@+id/cam" android:layout_width="75dp" android:layout_height="50dp" android:layout_weight="0.15" android:src="@drawable/cam" /&gt; &lt;ImageView android:id="@+id/browse" android:layout_width="75dp" android:layout_height="50dp" android:layout_weight="0.15" android:src="@drawable/folder" android:text="B" /&gt; &lt;ImageView android:id="@+id/upload" android:layout_width="75dp" android:layout_height="50dp" android:layout_weight="0.15" android:src="@drawable/run" android:text="A" /&gt; &lt;/LinearLayout&gt; &lt;LinearLayout android:id="@+id/baba" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical" &gt; &lt;ScrollView android:id="@+id/scroll" android:layout_width="fill_parent" android:layout_height="150dp" android:layout_weight="0.7" &gt; &lt;LinearLayout android:layout_width="fill_parent" android:layout_height="186dp" android:orientation="vertical" &gt; &lt;ImageView android:id="@+id/pic" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="1" /&gt; &lt;TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:text="Facial recognition" android:textAppearance="?android:attr/textAppearanceMedium" /&gt; &lt;TextView android:id="@+id/text3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:text="Small Text" android:textAppearance="?android:attr/textAppearanceSmall" /&gt; &lt;TextView android:id="@+id/avmarwe" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:text="Gender and age" android:textAppearance="?android:attr/textAppearanceMedium" /&gt; &lt;TextView android:id="@+id/text1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:text="Small Text" android:textAppearance="?android:attr/textAppearanceSmall" /&gt; &lt;TextView android:id="@+id/skahasd" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:text="Expression and mood" android:textAppearance="?android:attr/textAppearanceMedium" /&gt; &lt;TextView android:id="@+id/text2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:text="Small Text" android:textAppearance="?android:attr/textAppearanceSmall" /&gt; &lt;TextView android:id="@+id/dsfsfs" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:text="Celebrity Facial Match" android:textAppearance="?android:attr/textAppearanceMedium" /&gt; &lt;TextView android:id="@+id/text4" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:text="Small Text" android:textAppearance="?android:attr/textAppearanceSmall" /&gt; &lt;/LinearLayout&gt; &lt;/ScrollView&gt; &lt;/LinearLayout&gt; &lt;LinearLayout android:id="@+id/linearLayout1" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_gravity="bottom" &gt; &lt;Button android:id="@+id/c" android:layout_width="fill_parent" android:layout_height="50dp" android:layout_weight="0.7" android:text="" /&gt; &lt;Button android:id="@+id/share" android:layout_width="70dp" android:layout_height="50dp" android:layout_weight="0.3" android:text="" /&gt; &lt;/LinearLayout&gt; &lt;/LinearLayout&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload