切换同一个位置上的图片setCompoundDrawables
2016-08-02 09:49
316 查看
需求:
要在同一个位置上,如右上角,在不同的界面上,显示不同图片。
描述:
右上角,出现保存按钮(勾√)和添加按钮(+),在保存界面出现+,在提交界面出现√。
实现:
特别注意,要设置边界
如果不设置边界,图片会变形。
要在同一个位置上,如右上角,在不同的界面上,显示不同图片。
描述:
右上角,出现保存按钮(勾√)和添加按钮(+),在保存界面出现+,在提交界面出现√。
实现:
public void getRightChangeBtn(String str) { Drawable drawable; if (str.equals(RIGHT_SUBMIT)) { drawable = getResources().getDrawable(R.drawable.btn_true); drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight()); //设置边界 fbSave.setCompoundDrawables(null, null, drawable, null); } else if (str.equals(RIGHT_ADD)) { drawable = getResources().getDrawable(R.drawable.btn_add); drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight()); //设置边界 fbSave.setCompoundDrawables(null, null, drawable, null); } else if (str.equals(RIGHT_SAVE)) { drawable = getResources().getDrawable(R.drawable.btn_true); drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight()); //设置边界 fbSave.setCompoundDrawables(null, null, drawable, null); }else if (str.equals(RIGHT_NULL)) { fbSave.setVisibility(View.INVISIBLE); } fbSave.setWidth(fbSave.getWidth()); fbSave.setPadding(fbSave.getPaddingLeft(), fbSave.getPaddingTop(), fbSave.getPaddingRight(), fbSave.getPaddingBottom()); }
特别注意,要设置边界
drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight()); //设置边界
如果不设置边界,图片会变形。
相关文章推荐
- android TextView如何通过setCompoundDrawables调整文字和图片的位置(文字显示在图片内)?
- setCompoundDrawables不显示图片
- android中getCompoundDrawables()方法,设置文本框中图片的位置
- setCompoundDrawables不显示图片
- Android中的Button可同时设置图片跟文字(setCompoundDrawablesWithIntrinsicBounds)
- Android TextView setcompounddrawables 图片不显示的问题
- android 设置图片小妙招 setCompoundDrawables与setCompoundDrawablesWithIntrinsicBounds
- android 设置图片小妙招 setCompoundDrawables与setCompoundDrawablesWithIntrinsicBounds
- Android setcompounddrawables 无效,图片不显示
- textview.setCompoundDrawables不显示图片
- 一个很好的图片切换js
- 16—【Android游戏开发十六】Android Gesture之【触摸屏手势识别】操作!利用触摸屏手势实现一个简单切换图片的功能
- 推荐一个纵向图片slider切换效果
- 简短几句jquery代码的实现一个图片向上滚动切换
- 简短几句jquery代码的实现一个图片向上滚动切换。
- 【Android游戏开发十六】Android Gesture之【触摸屏手势识别】操作!利用触摸屏手势实现一个简单切换图片的功能!
- 一个简单的图片切换 jQuery 插件
- 【Android游戏开发十六】Android Gesture之【触摸屏手势识别】操作!利用触摸屏手势实现一个简单切换图片的功能!
- jQuery 一个图片切换的插件
- 【Android2D游戏开发十六】(上文之触摸屏手势)详解Android Gesture 手势操作!利用手势实现一个简单切换图片的功能!