【发布时间】:2012-12-03 15:14:03
【问题描述】:
我正在尝试在运行时设置 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);
Images 的宽度使用 fill_parent 进行缩放,但未正确拉伸高度。
如果我使用
topView.setImageResource(R.drawable.button_where_citymap); 相反,一切正常,但我确实想在运行时从文件路径设置源代码。
我做错了什么?
【问题讨论】:
标签: android android-layout android-button android-image