我尝试在我的ImageButton中动态地编码这个Activity,但是它看起来非常不同。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);有人看到我的错误了吗?谢谢!
发布于 2014-12-22 12:18:53
将ImageButtons的宽度设置为fill_parent,并对拥抱左侧边距的图像使用缩放类型fitStart,对右边的图像使用fitEnd。应该能做到这一点,至少就你的例子形象而言。如果图像的比例宽度超过屏幕宽度,您可能会遇到一些间隔问题,但它应该适用于您。
https://stackoverflow.com/questions/17278298
复制相似问题