Q:

How to save linearLayout and it's item as a image?

I am developing a quote app, I want to set image in background of linear layout not in ImageView in android.
my linearLayout contain two text view.
I want to save this Layout in a gallery.Can anyone please tell how may I do this
The code that I used is:
in the XML:
<!-- language: lang-xml -->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content">

<android.support.v7.widget.CardView
    android:id="@+id/card_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="center"
    android:layout_margin="@dimen/card_margin"
    android:elevation="3dp"
    card_view:cardCornerRadius="@dimen/card_album_radius">

    <RelativeLayout

        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <LinearLayout
            android:id="@+id/lnquote1"        //my layout 
            android:layout_width="match_parent"
            android:layout_height="@dimen/_150sdp"
            android:gravity="center"
            android:background="@drawable/cheese_5"
            android:orientation="vertical">

            <LinearLayout
                android:id="@+id/lnquote"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:gravity="center"
                android:background="@drawable/scrim"
                android:orientation="vertical">

                <TextView
                    android:id="@+id/quote"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:textIsSelectable="true"
                    android:paddingLeft="@dimen/album_title_padding"
                    android:paddingRight="@dimen/album_title_padding"
                    android:paddingTop="@dimen/album_title_padding"
                    android:textColor="@color/white"
                    android:text="Quotes"
                    android:gravity="center"
                    android:typeface="serif"
                    android:textSize="@dimen/album_title" />

                <TextView
                    android:id="@+id/author"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:gravity="end"
                    android:paddingLeft="@dimen/album_title_padding"
                    android:paddingRight="@dimen/album_title_padding"
                    android:paddingTop="@dimen/album_title_padding"
                    android:layout_marginTop="10dp"
                    android:layout_marginBottom="5dp"
                    android:text=" -Author"
                    android:textColor="@color/white"
                    android:textSize="@dimen/album_title" />

            </LinearLayout>

        </LinearLayout>

        <View
            android:id="@+id/viline"
            android:layout_width="match_parent"
            android:layout_height="1dp"
            android:layout_below="@id/lnquote1"
            android:layout_marginTop="2dp"
            android:layout_marginLeft="15dp"
            android:layout_marginRight="15dp"
            android:layout_marginBottom="5dp"
            android:background="@android:color/darker_gray" />

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="40dp"
            android:orientation="horizontal"
            android:layout_below="@id/viline">

            <LinearLayout
                android:id="@+id/lncopy"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:gravity="center_horizontal|center_vertical"
                android:layout_weight="1">

                <ImageView
                    android:id="@+id/imgcopy"
                    android:layout_width="25dp"
                    android:layout_height="25dp"
                    android:scaleType="centerInside"
                    android:gravity="center"
                    android:background="@drawable/cop" />

                <TextView
                    android:id="@+id/txtcopy"
                    android:layout_width="wrap_content"
                    android:gravity="center"
                    android:layout_height="@dimen/ic_album_overflow_height"
                    android:layout_alignParentRight="true"
                    android:layout_marginLeft="2dp"
                    android:textColor="@color/album_title"
                    android:text="Copy"/>

            </LinearLayout>
            <LinearLayout
                android:id="@+id/lnshare"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:gravity="center_horizontal|center_vertical"
                android:layout_weight="1">

                <ImageView
                    android:id="@+id/imgshare"
                    android:layout_width="25dp"
                    android:layout_height="25dp"
                    android:scaleType="centerInside"
                    android:background="@drawable/sha" />

                <TextView
                    android:id="@+id/txtshare"
                    android:layout_width="wrap_content"
                    android:gravity="center"
                    android:layout_height="@dimen/ic_album_overflow_height"
                    android:layout_alignParentRight="true"
                    android:layout_marginLeft="4dp"
                    android:textColor="@color/album_title"
                    android:text="Share"/>

            </LinearLayout>
            <LinearLayout
                android:id="@+id/lnfav"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:gravity="center_horizontal|center_vertical"
                android:layout_weight="1">

                <ImageView
                    android:id="@+id/imgfav"
                    android:layout_width="25dp"
                    android:layout_height="25dp"
                    android:scaleType="centerInside"
                    android:tag="bg1"
                     />

            </LinearLayout>

        </LinearLayout>

    </RelativeLayout>

</android.support.v7.widget.CardView>

Any help would be highly appreciated

A:

Simply use,    
LinearLayout view = (LinearLayout)findViewById(R.id.linearlayout);
view.setDrawingCacheEnabled(true);
view.buildDrawingCache();
Bitmap bm = view.getDrawingCache();

