setScaleType无法使图片拉伸显示到ImageButton上
ImageButton bt = new ImageButton(mToolBar.getContext());
bt.setImageResource(resId);
bt.setBackgroundColor(Color.BLACK);
bt.setScaleType(ImageButton.ScaleType.FIT_CENTER);
bt.setOnClickListener(listener);
mToolBar.addView(bt,new LinearLayout.LayoutParams(72,72));
图片都是是 128*128的,在XML文件里添加的ImageButton是可以的
<LinearLayout
android:id="@+id/linearLayoutToolBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<ImageButton
android:id="@+id/drawline"
android:layout_width="72dp"
android:layout_height="72dp"
android:scaleType="fitCenter"
android:src="@drawable/ic_line"
android:background="#ff000000" />
</LinearLayout>
如图,小的那个是代码里添加进去的,大的哪些是XML文件里写的,不知道这是咋回事,图片都是是 128*128的。
[解决办法]
光看是解决不了问题的。试着改一些地方,观察呢。
1.你把mToolBar.addView(bt,new LinearLayout.LayoutParams(72,72));
里面的数字改大一点,比如(200,300)。
2.scaleType这个属性去掉试试。
3.其他地方有可疑的参数都修改观察一下。
不行的话我也不清楚了,那只有召唤大神帮忙了- -