我正在尝试在运行时设置 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);
改用,一切正常,但我确实想在运行时从文件路径设置源。
我究竟做错了什么?