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

Untitled

By: a guest on Apr 29th, 2012  |  syntax: None  |  size: 1.60 KB  |  hits: 21  |  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. Referring to my custom BitmapDrawable from android:src in a resource XML
  2. <?xml version="1.0" encoding="utf-8"?>
  3. <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
  4.     android:id="@+id/frameLayout1"
  5.     android:layout_width="wrap_content"
  6.     android:layout_height="wrap_content" >
  7.  
  8.     <ImageView
  9.         android:id="@+id/ivFrame"
  10.         android:adjustViewBounds="true"
  11.         android:layout_width="wrap_content"
  12.         android:layout_height="wrap_content"
  13.         android:src="@drawable/frame" />
  14.  
  15.     <ImageView
  16.         android:id="@+id/ivContent"
  17.         android:adjustViewBounds="true"
  18.         android:layout_width="wrap_content"
  19.         android:layout_height="wrap_content"
  20.         android:src="@drawable/content" />
  21.  
  22. </FrameLayout>
  23.        
  24. public class CustomDrawable extends BitmapDrawable {
  25.  
  26.  
  27.     public CustomDrawable(Resources res, Bitmap bitmap) {
  28.         super(res, bitmap);
  29.         // TODO Auto-generated constructor stub
  30.     }
  31.  
  32.     public CustomDrawable(Resources res, InputStream is) {
  33.         super(res, is);
  34.         // TODO Auto-generated constructor stub
  35.     }
  36.  
  37.     public CustomDrawable(Resources res, String filepath) {
  38.         super(res, filepath);
  39.         // TODO Auto-generated constructor stub
  40.     }
  41.  
  42.     public CustomDrawable(Resources res) {
  43.         super(res);
  44.         // TODO Auto-generated constructor stub
  45.     }
  46.  
  47.     @Override
  48.     protected void onBoundsChange(Rect bounds) {
  49.         Log.d(Constants.LOG_TAG,"CustomDrawable.onBoundsChanged: "+bounds);
  50.         super.onBoundsChange(bounds);
  51.     }
  52.  
  53. }
  54.        
  55. ((ImageView) findViewById(R.id.ivContent)).setImageDrawable(new CustomDrawable(...))