This tag and its children can be replaced by one <TextView/> and a compound drawable
2016-06-08 09:30
639 查看
1.当是以下布局,LinearLayout会报警告:This tag and its children can be replaced by one and a compound drawable
2.修改方法:将TextView和ImageVie合成一个,直接在xml中利用TextView的 android:drawableTop、android:drawableRight等属性指定!如下:
3.如果要在代码中设置textview上下左右图片,使用以下方法:
但Drawable对象必须使用这个方法,否则图片不展示
在textview上方设置图片的总体使用方法:
<LinearLayout android:id="@+id/ll_assort_video" android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:orientation="vertical"> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/category_icon_video"/> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/video"/> </LinearLayout>
2.修改方法:将TextView和ImageVie合成一个,直接在xml中利用TextView的 android:drawableTop、android:drawableRight等属性指定!如下:
<LinearLayout android:id="@+id/ll_assort_video" android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:orientation="vertical"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/video" android:drawableTop="@drawable/category_icon_video"/> </LinearLayout>
3.如果要在代码中设置textview上下左右图片,使用以下方法:
setCompoundDrawables(Drawable left, Drawable top, Drawable right, Drawable bottom)
但Drawable对象必须使用这个方法,否则图片不展示
setBounds(int left, int top, int right, int bottom)
在textview上方设置图片的总体使用方法:
Drawable drawable= getResources().getDrawable(R.drawable.drawable); drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight()); textview.setCompoundDrawables(null,drawable,null,null);
相关文章推荐
- 使用C++实现JNI接口需要注意的事项
- Android IPC进程间通讯机制
- Android Manifest 用法
- [转载]Activity中ConfigChanges属性的用法
- Android之获取手机上的图片和视频缩略图thumbnails
- Android之使用Http协议实现文件上传功能
- Android学习笔记(二九):嵌入浏览器
- android string.xml文件中的整型和string型代替
- i-jetty环境搭配与编译
- android之定时器AlarmManager
- android wifi 无线调试
- Android Native 绘图方法
- Android java 与 javascript互访(相互调用)的方法例子
- android 代码实现控件之间的间距
- android FragmentPagerAdapter的“标准”配置
- Android"解决"onTouch和onClick的冲突问题
- android:installLocation简析
- android searchView的关闭事件
- SourceProvider.getJniDirectories