我尝试在我的 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" />
Here my Java-Code to generate this in my activity:
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);
有人看到我的错误吗?谢谢!
最佳答案
将 ImageButtons 的宽度设置为 fill_parent 并对紧靠左边距的图像使用 scaletype fitStart,对右侧的图像使用 fitEnd。至少就您的示例图像而言,应该可以解决问题。如果图像的比例宽度超过屏幕宽度,您可能会遇到一些间距问题,但这应该适合您。
关于android - 带 ScaleType 的 ImageButton Android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17278298/