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的。
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的。
解决方案 »
- 奇怪了Eclipse找不到SDK 创建AVD时target为灰色
- android google map导航
- Oauth 认证问题
- android客户端获取服务器端图片问题!
- 求答案:在HP官网看到的,图片360度旋转,由鼠标控制,这个效果怎么弄?
- jsoup解析td标签的html网页
- 通过JNI启动 init.rc 新添加的service 失败,想请教
- Android中ListView的item为EditText,点击EditText出现键盘但马上键盘就退出了
- java.lang.ClassNotFoundException: 是什么意思?
- 关于手机对HDMI支持的硬件要求
- android Notification中添加一个按钮如何监听按钮事件
- android和javaweb的选择
是不是你这行限定死了?
把上面括号中的值,还有android:layout_width="72dp"中的值,换成wrap_content试试呢
就是那个代码里动态创建的不知道怎么显示的时候小那么多,我的想法是动态创建的应该和XML里创建的显示的大小一样啊。
里面的数字改大一点,比如(200,300)。2.scaleType这个属性去掉试试。3.其他地方有可疑的参数都修改观察一下。不行的话我也不清楚了,那只有召唤大神帮忙了- -
宽高改大一点就超出了button的范围显示了,感觉不是居中显示的。
宽高改小些显示的小一些,还是居中。
不用scaleType显示的比XML里的那个更大一些。