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的。
解决方案 »
- android做背单词软件该如何存储单词
- activity跳转后 service是否工作
- LuaState L = LuaStateFactory.newLuaState();
- 高分求解答 Android中如何使用listview进行分页
- 小妹请教Activity互相发送消息问题!
- monkey 和 sdk
- 初次接触android,我应该下载哪些软件?最新版本的请大家给列出来
- Android 怎么把多个应用显示在一个应用程序里面
- Android 连接指定Wifi 的问题
- android studio 给app上传头像错误
- android Notification中添加一个按钮如何监听按钮事件
- android和javaweb的选择
是不是你这行限定死了?
把上面括号中的值,还有android:layout_width="72dp"中的值,换成wrap_content试试呢
就是那个代码里动态创建的不知道怎么显示的时候小那么多,我的想法是动态创建的应该和XML里创建的显示的大小一样啊。
里面的数字改大一点,比如(200,300)。2.scaleType这个属性去掉试试。3.其他地方有可疑的参数都修改观察一下。不行的话我也不清楚了,那只有召唤大神帮忙了- -
宽高改大一点就超出了button的范围显示了,感觉不是居中显示的。
宽高改小些显示的小一些,还是居中。
不用scaleType显示的比XML里的那个更大一些。