2

私はFrameLayout次のようにしています(両方の android:src 属性がフォルダー内の .png ファイルを参照してい/res/drawableます):

<?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>

ここで、2 番目のデバッグを行う必要がありますImageView(これは を参照してい@drawable/contentます)。この目的のために、次のようにカスタム BitmapDrawable を作成しました。

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);
    }

}

質問:

  1. CustomDrawableXML でmy を指定する方法(および使用するように指示する方法@drawable/content)
  2. ImageView次に、レイアウト XML で に my を指すように指示するにはどうすればよいCustomDrawableですか?
4

1 に答える 1

2

xml ファイルでは実行できませんが、コードでは実行できます。

((ImageView) findViewById(R.id.ivContent)).setImageDrawable(new CustomDrawable(...))
于 2012-02-13T12:38:26.210 に答える