【发布时间】:2013-06-24 14:43:31
【问题描述】:
我尝试在我的Activity 中动态编码这个ImageButton,但它看起来非常不同。 ScaleType 似乎不起作用。这是ImageButton 我想要的方式:
<ImageButton
android:id="@+id/imageButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:background="@null"
android:scaleType="fitStart"
android:src="@drawable/rot" />
这里是我的 Java 代码,用于在我的活动中生成它:
ImageButton field = new ImageButton(this);
LayoutParams param = new linearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT, 1.0f);
field.setLayoutParams(param);
field.setScaleType(ScaleType.FIT_START);
field.setBackgroundResource(0);
field.setAdjustViewBounds(true);
field.setImageResource(R.drawable.rot);
有人看到我的错误吗?谢谢!
【问题讨论】:
-
图片来源不同。由于您使用的是
WRAP_CONTENT,可能会导致它的大小不同。 -
图片来源只是一个例子
-
当我将 WRAP_CONTENT 更改为 MATCH_PARENT 时,它不会改变任何东西。他完全忽略了“setScaleType”。
标签: android imagebutton