title: How to place 4 bitmaps in a large notification icon?
body: <p>I want to place 4 bitmaps in a large notification icon. Each bitmap should be placed in one quarter of the icon.</p>
  
  <p>I've created a layout "notification_large_icon_layout.xml" for the icon:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:id="@+id/notification_large_icon_layout"
      android:layout_width="match_parent"
      android:layout_height="match_parent" &gt;
  
      &lt;ImageView
          android:id="@+id/thumbnail1"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_alignParentLeft="true"
          android:layout_alignParentTop="true"
          android:src="@drawable/ic_contact_picture" /&gt;
  
      &lt;ImageView
          android:id="@+id/thumbnail2"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_alignParentRight="true"
          android:layout_alignParentTop="true"
          android:layout_alignRight="@+id/thumbnail1"
          android:src="@drawable/ic_contact_picture" /&gt;
  
      &lt;ImageView
          android:id="@+id/thumbnail3"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_alignBottom="@+id/thumbnail1"
          android:layout_alignParentBottom="true"
          android:layout_alignParentLeft="true"
          android:src="@drawable/ic_contact_picture" /&gt;
  
      &lt;ImageView
          android:id="@+id/thumbnail4"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_alignBottom="@+id/thumbnail2"
          android:layout_alignRight="@+id/thumbnail3"
          android:layout_alignParentBottom="true"
          android:layout_alignParentRight="true"
          android:src="@drawable/ic_contact_picture" /&gt;
  
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>And I have added the following code into my notification function:</p>
  
  <pre><code>...
  // Create bitmap and scale it to 1/2
  Bitmap bitmap = BitmapFactory.decodeStream(cr.openInputStream(rowUri));
  Resources res = getApplicationContext().getResources();
  int height = (int) res.getDimension(android.R.dimen.notification_large_icon_height);
  int width = (int) res.getDimension(android.R.dimen.notification_large_icon_width);
  bitmap = Bitmap.createScaledBitmap(bitmap, width/2, height/2, false);
  
  // Inflate the layout for the large icon                            
  LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  View view = inflater.inflate(R.layout.notification_large_icon_layout, null);
  
  // Copy bitmap to the 4 views
  ImageView thumbnailView = (ImageView) view.findViewById(R.id.thumbnail1);
  thumbnailView.setImageBitmap(bitmap);
  thumbnailView = (ImageView) view.findViewById(R.id.thumbnail2);
  thumbnailView.setImageBitmap(bitmap);
  thumbnailView = (ImageView) view.findViewById(R.id.thumbnail3);
  thumbnailView.setImageBitmap(bitmap);
  thumbnailView = (ImageView) view.findViewById(R.id.thumbnail4);
  thumbnailView.setImageBitmap(bitmap);
  
  // Convert view to bitmap
  Bitmap icon = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
  Canvas canvas = new Canvas(icon);
  view.draw(canvas);
  
  notificationBuilder.setLargeIcon(icon);
  ...
  </code></pre>
  
  <p>It doesn't work. The icon is only gray.</p>
  
  <p><strong>Change 1:</strong></p>
  
  <p>I've changed the layout as follows (less flexible):</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:id="@+id/notification_large_icon_layout"
      android:layout_width="128dp"
      android:layout_height="128dp" &gt;
  
      &lt;ImageView
          android:id="@+id/thumbnail1"
          android:layout_width="64dp"
          android:layout_height="64dp"
          android:layout_alignParentLeft="true"
          android:layout_alignParentTop="true" /&gt;
  
      &lt;ImageView
          android:id="@+id/thumbnail2"
          android:layout_width="64dp"
          android:layout_height="64dp"
          android:layout_alignParentRight="true"
          android:layout_alignParentTop="true"
          android:layout_toRightOf="@+id/thumbnail1" /&gt;
  
      &lt;ImageView
          android:id="@+id/thumbnail3"
          android:layout_width="64dp"
          android:layout_height="64dp"
          android:layout_alignParentBottom="true"
          android:layout_alignParentLeft="true"
          android:layout_below="@+id/thumbnail1" /&gt;
  
      &lt;ImageView
          android:id="@+id/thumbnail4"
          android:layout_width="64dp"
          android:layout_height="64dp"
          android:layout_alignParentBottom="true"
          android:layout_alignParentRight="true"
          android:layout_below="@+id/thumbnail2"
          android:layout_toRightOf="@+id/thumbnail3" /&gt;
  
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>And I've changed the function like this:</p>
  
  <pre><code>...
  // Create bitmap and scale it to 1/2
  Bitmap bitmap = BitmapFactory.decodeStream(cr.openInputStream(rowUri));
  Resources res = getApplicationContext().getResources();
  int height = (int) res.getDimension(android.R.dimen.notification_large_icon_height);
  int width = (int) res.getDimension(android.R.dimen.notification_large_icon_width);
  bitmap = Bitmap.createScaledBitmap(bitmap, width/2, height/2, false);
  
  // Inflate the layout for the large icon                            
  LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  View view = inflater.inflate(R.layout.notification_large_icon_layout, null);
  
  view.measure(MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY));
  view.layout(0, 0, view.getMeasuredWidth(), view.getMeasuredHeight()); 
  
  // Copy bitmap to the 4 views
  ImageView thumbnailView = (ImageView) view.findViewById(R.id.thumbnail1);
  thumbnailView.setImageBitmap(bitmap);
  thumbnailView = (ImageView) view.findViewById(R.id.thumbnail2);
  thumbnailView.setImageBitmap(bitmap);
  thumbnailView = (ImageView) view.findViewById(R.id.thumbnail3);
  thumbnailView.setImageBitmap(bitmap);
  thumbnailView = (ImageView) view.findViewById(R.id.thumbnail4);
  thumbnailView.setImageBitmap(bitmap);
  
  // Convert view to bitmap
  Bitmap icon = Bitmap.createBitmap(view.getMeasuredWidth(), view.getMeasuredHeight(), Bitmap.Config.ARGB_8888);
  Canvas canvas = new Canvas(icon);
  view.draw(canvas);
  
  notificationBuilder.setLargeIcon(icon);
  ...
  </code></pre>
  
  <p>Now I can see 1 bitmap with half resolution/density. Seems like the 4 bitmaps are overlapped.</p>
  
  <p><strong>Change 2:</strong></p>
  
  <p>The following code works:</p>
  
  <pre><code>...
  // Create bitmap and scale it to 1/2
  Bitmap bitmap = BitmapFactory.decodeStream(cr.openInputStream(rowUri));
  Resources res = getApplicationContext().getResources();
  int height = (int) res.getDimension(android.R.dimen.notification_large_icon_height);
  int width = (int) res.getDimension(android.R.dimen.notification_large_icon_width);
  bitmap = Bitmap.createScaledBitmap(bitmap, width/2, height/2, false);
  
  // Inflate the layout for the large icon
  LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  View view = inflater.inflate(R.layout.notification_large_icon_layout, null);
  view.measure(MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY));
  view.layout(0, 0, view.getMeasuredWidth(), view.getMeasuredHeight()); 
  
  // Copy bitmap to the 4 views
  ImageView thumbnailView = (ImageView) view.findViewById(R.id.thumbnail1);
  thumbnailView.setBottom(height/2);
  thumbnailView.setRight(width/2);
  thumbnailView.setImageBitmap(bitmap);
  thumbnailView = (ImageView) view.findViewById(R.id.thumbnail2);
  thumbnailView.setBottom(height/2);
  thumbnailView.setLeft(width/2);
  thumbnailView.setImageBitmap(bitmap);
  thumbnailView = (ImageView) view.findViewById(R.id.thumbnail3);
  thumbnailView.setTop(height/2);
  thumbnailView.setRight(width/2);
  thumbnailView.setImageBitmap(bitmap);
  thumbnailView = (ImageView) view.findViewById(R.id.thumbnail4);
  thumbnailView.setTop(height/2);
  thumbnailView.setLeft(width/2);
  thumbnailView.setImageBitmap(bitmap);
  
  // Convert view to bitmap
  Bitmap icon = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
  Canvas canvas = new Canvas(icon);
  view.draw(canvas);
  
  notificationBuilder.setLargeIcon(icon);
  ...
  </code></pre>
  
  <p>But I wonder, why I have to explicitly define the positions of the bitmaps.</p>
  
  <p>Btw: The following snippets A and B have the same result. I can't see any difference.</p>
  
  <p>Snippet A:</p>
  
  <pre><code>Bitmap icon = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
  Canvas canvas = new Canvas(icon);
  view.draw(canvas);
  </code></pre>
  
  <p>Snippet B:</p>
  
  <pre><code>view.setDrawingCacheEnabled(true);
  Bitmap icon = Bitmap.createBitmap(view.getDrawingCache());
  view.setDrawingCacheEnabled(false);
  </code></pre>