title: Convert relative layout to bitmap and save it to phone gallery with it's child element
body: <p>I am trying to convert <code>RelativeLayout</code> to bitmap and want to save it to phone gallery with it's child element. But when I am saving it, only one image is saved in gallery and the other child are not saved.</p>
  
  <pre><code>public class Result extends Activity implements android.view.View.OnClickListener{
      private MaskAdjuster mIV;
      private Bitmap mBitmap,b;
      private Bundle getValues;
      private Button save,moreApp;
      private ImageView mask;
      private BitmapDrawable d;
      private static File APP_FILE_PATH = new File("/sdcard/rISHABH/");
      private int x,y;
      private int []epx=null;
      private int []epy=null;
      private int []lpx=null;
      private int []lpy=null;
      private float eyedistance;
      private int count;
      public String filename;
      @Override
      protected void onCreate(Bundle savedInstanceState) {
      // TODO Auto-generated method stub
      super.onCreate(savedInstanceState);
      mIV=new MaskAdjuster(this);
      setContentView(R.layout.result);
      initialize();
      b=getIntent().getParcelableExtra("bitmap");
      mBitmap=b.copy(Bitmap.Config.RGB_565, true);
      getValues=getIntent().getBundleExtra("bundle");
      epx=getValues.getIntArray("eyelocationX");
      epy=getValues.getIntArray("eyelocationY");
      lpx=getValues.getIntArray("liplocationX");
      lpy=getValues.getIntArray("liplocationY");
  
  
      eyedistance=getValues.getFloat("eyedistance");
      count=getValues.getInt("count");
      mIV=(MaskAdjuster)findViewById(R.id.iv_resultface);
      mIV.setImageBitmap(mBitmap);
      mIV.setDisplayPoints(epx, epy,lpx,lpy, count * 2, eyedistance);
      mIV.invalidate();
      mask.setImageBitmap(MaskAdjuster.getFace());
      save.setOnClickListener(this);
      moreApp.setOnClickListener(this);
      }
  
  
      private void initialize() {
      save=(Button)findViewById(R.id.btn_save);
      moreApp=(Button)findViewById(R.id.btn_more_app);
      mask=(ImageView)findViewById(R.id.iv_mask);
      }
  
  
      @Override
      protected void onPause() {
      // TODO Auto-generated method stub
  
      super.onPause();
  
      b.recycle();
      finish();
  
      }
  
  
      @Override
      public void onClick(View v) {
      switch (v.getId()) {
      case R.id.btn_save:
  
      try{
      saveandforward();
  
  
      Toast.makeText (getApplicationContext(), 
      "Image has been saved to Gallery(SD card) by name : " + APP_FILE_PATH +            filename, Toast.LENGTH_LONG).show ();
  
      }catch (Exception e) {
      e.printStackTrace();
      }
  
      break;
      case R.id.btn_more_app:
  
      break;
  
      default:
      break;
      }
      }
  
  
  
      void saveandforward(){
      Bitmap bm=null;
      try {
      Calendar cal = Calendar.getInstance();
      SimpleDateFormat sdf = new SimpleDateFormat ("yyyyMMddHHmmss");
      filename = sdf.format(cal.getTime());
  
      final FileOutputStream out = new FileOutputStream(new File      (APP_FILE_PATH     +filename+".png"));
      try{
      View vs = (View)findViewById(R.id.Frame_layout);
      bm = loadBitmapFromView(vs);
  
      }
      catch(Exception e)
      {
      Log.e("meesge",e.getMessage()); 
  
      }
      bm.compress(Bitmap.CompressFormat.PNG, 90, out);
      out.flush();
      out.close();
  
      }catch (Exception e) {
      e.printStackTrace();
      }
  
      }
      public static Bitmap loadBitmapFromView(View v) {
      Bitmap b = Bitmap.createBitmap(320,480, Bitmap.Config.RGB_565);
      Canvas c = new Canvas(b);
      v.draw(c);
      return b;
  
           }
      }
  </code></pre>
  
  <p>xml is here</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:background="@drawable/bg"&gt;
  &lt;FrameLayout
  android:id="@+id/Frame_layout"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:layout_centerHorizontal="true"
  android:layout_centerVertical="true"
  &gt;
  &lt;com.shagun.agemyface.MaskAdjuster
  android:id="@+id/iv_resultface"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  /&gt;
  &lt;ImageView
  android:id="@+id/iv_mask"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  
  /&gt;
  &lt;/FrameLayout&gt;
  &lt;Button 
  android:id="@+id/btn_save"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:layout_alignParentBottom="true"
  android:layout_alignParentLeft="true"
  android:background="@drawable/save"/&gt;
  
  &lt;Button 
  android:id="@+id/btn_more_app"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:layout_alignParentBottom="true"
  android:layout_alignParentRight="true"
  android:text="More App"/&gt;
  
  
  
  
  &lt;/RelativeLayout&gt;
  </code></pre>