Reputation: 10672
I have a FrameLayout
as follows (both android:src attributes refer to .png files in /res/drawable
folder):
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/frameLayout1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<ImageView
android:id="@+id/ivFrame"
android:adjustViewBounds="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/frame" />
<ImageView
android:id="@+id/ivContent"
android:adjustViewBounds="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/content" />
</FrameLayout>
Now, I need to do some debugging for the second ImageView
(that referring to @drawable/content
). For this purpose, I created a Custom BitmapDrawable as follows:
public class CustomDrawable extends BitmapDrawable {
public CustomDrawable(Resources res, Bitmap bitmap) {
super(res, bitmap);
// TODO Auto-generated constructor stub
}
public CustomDrawable(Resources res, InputStream is) {
super(res, is);
// TODO Auto-generated constructor stub
}
public CustomDrawable(Resources res, String filepath) {
super(res, filepath);
// TODO Auto-generated constructor stub
}
public CustomDrawable(Resources res) {
super(res);
// TODO Auto-generated constructor stub
}
@Override
protected void onBoundsChange(Rect bounds) {
Log.d(Constants.LOG_TAG,"CustomDrawable.onBoundsChanged: "+bounds);
super.onBoundsChange(bounds);
}
}
Question:
CustomDrawable
in XML (and tell it to use @drawable/content
)ImageView
in the layout XML to point to my CustomDrawable
?Upvotes: 2
Views: 1195
Reputation: 8612
You can't do it xml file, but you can do in code:
((ImageView) findViewById(R.id.ivContent)).setImageDrawable(new CustomDrawable(...))
Upvotes: 2