実行時に ImageButton のイメージを設定しようとしています。画面の幅いっぱいに表示し、正しく拡大縮小するために必要なだけの高さのスペースを使用する必要があります。
ImageButton は次のように宣言されます。
<ImageButton
android:id="@+id/map_plan_topview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:onClick="onMapImageClicked"
android:background="#0000"
android:scaleType="fitXY" />
今、私は次のように画像を設定しようとしています:
ImageButton topView = (ImageButton) findViewById(R.id.map_plan_topview);
Drawable d = Drawable.createFromPath(path);
topView.setImageDrawable(d);
画像の幅は fill_parent でスケーリングされますが、高さが正しく引き伸ばされません。代わりに使用
topView.setImageResource(R.drawable.button_where_citymap);
すると、すべて正常に動作しますが、実行時にファイルパスからソースを設定したいと考えています。
私は何を間違っていますか?