Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 4th, 2012  |  syntax: None  |  size: 1.39 KB  |  hits: 11  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Unexpected LayerDrawable behavior when drawing layers containing InsetDrawable's
  2. <?xml version="1.0" encoding="utf-8"?>
  3. <layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
  4.  
  5.     <item>
  6.         <shape android:shape="oval" >
  7.             <solid android:color="#00ff00" />
  8.         </shape>
  9.     </item>
  10.     <item>
  11.         <inset
  12.             android:insetBottom="4dp"
  13.             android:insetLeft="4dp"
  14.             android:insetRight="4dp"
  15.             android:insetTop="4dp" >
  16.             <shape android:shape="rectangle" >
  17.                 <solid android:color="#ff0000" />
  18.             </shape>
  19.         </inset>
  20.     </item>
  21.     <item>
  22.         <shape android:shape="oval" >
  23.             <solid android:color="#0000ff" />
  24.         </shape>
  25.     </item>
  26.  
  27. </layer-list>
  28.        
  29. @Override
  30. protected void onBoundsChange(Rect bounds) {
  31.     final ChildDrawable[] array = mLayerState.mChildren;
  32.     final int N = mLayerState.mNum;
  33.     int padL=0, padT=0, padR=0, padB=0;
  34.     for (int i=0; i<N; i++) {
  35.         final ChildDrawable r = array[i];
  36.         r.mDrawable.setBounds(bounds.left + r.mInsetL + padL,
  37.                               bounds.top + r.mInsetT + padT,
  38.                               bounds.right - r.mInsetR - padR,
  39.                               bounds.bottom - r.mInsetB - padB);
  40.         padL += mPaddingL[i];
  41.         padR += mPaddingR[i];
  42.         padT += mPaddingT[i];
  43.         padB += mPaddingB[i];
  44.     }
  45. }