Android笔记之TextView中使用Drawable
2015-05-21 12:05
337 查看
1.在xml文件中的使用
2.在java文件中的使用
<!--android:drawableLeft设置在文字在左边添加一个图片, 还有drawableRight/drawableTop/drawableBottom可以选择, android:drawablePadding设置图片与文字间的间距,只控制 与文字的间距,不影响图片周围空间 --> <TextView android:id="@+id/lth_item_praise_tv" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_vertical" android:drawableLeft="@drawable/praise_flower_s" android:drawablePadding="5dp" android:text="1朵" android:textColor="@color/red" android:textSize="@dimen/tv05" />
2.在java文件中的使用
Drawable drawable = getResources().getDrawable(R.mipmap.ic_launcher); /** * 方法一 */ // 必须设置图片的显示大小,否则不显示 // drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight()); // 参数分别对应left、top、right、bottom方向放置图片 // tv.setCompoundDrawables(null, null, null, drawable); //方法一结束---------- /** * 方法二 */ tv.setCompoundDrawablesWithIntrinsicBounds(null, drawable, null, null); //方法二结束---------- tv.setCompoundDrawablePadding(5);
相关文章推荐
- android应用开发揭秘例4-3笔记(TextView的使用)
- android应用开发揭秘examples_04-10笔记(AutoCompleteTextView和MultiAutoCompleteTextView使用)
- 使用代码控制Android的TextView属性drawableLeft
- ANDROID笔记:TextView的简单使用
- ANDROID笔记:AutoCompleteTextView的简单使用
- android textview drawableleft使用时遇到的问题
- Android布局技巧:使用TextView的drawable属性
- Android 高级UI设计笔记05:使用TextView实现跑马灯的效果
- Android使用代码为textview设置drawableLeft或drawableRight
- Android控件笔记——使用TextView实现跑马灯效果
- 【Android基础笔记04】Spinner 和 AutoCompleteTextView 基本适配器控件的使用
- Android中EditView TextView (padding失效)使用setBackgroundDrawable或setBackgroundResource则xml中设置的 Padding失效
- Android中可下拉选择的AutoCompleteTextView的使用
- Android TextView 常见问题与使用总结
- Android使用代码为textview设置drawableLeft
- Android使用TextView实现跑马灯效果
- Android中TextView使用SpannableString设置复合文本
- Android使用TextView,设置onClick属性无效解决的方法
- Android中使用TextView实现微博@功能
- Android 判断ImageView使用的图片是drawable文件夹下的某个图片