Android 实现TextView后面跟随一个高度和宽度固定的ImageView
2016-06-17 16:16
441 查看
安卓实现TextView后面跟随一个高度和宽度固定的ImageView(不要问我为什么不直接用drawableRight,因为宽高不好控制)
TextView只为1行,即singleLine为true,宽度不定,要求TextView和ImageView站在同一排。
如图:
直接上代码:
Linearlayout里面的weight其实很好用,但是有朋友可能会想着,为什么只给TextView加weight属性,为什么不给ImageView加。weight是权重的意思,给组件加了该属性之后,该组件就会与其他的同级组件比较权重,然后再布局。闲的无聊的可以去试试把ImageView加weight,或者把TextView的weight取消试试效果。
TextView只为1行,即singleLine为true,宽度不定,要求TextView和ImageView站在同一排。
如图:
直接上代码:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_margin="16dp" android:orientation="vertical"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text=" 安卓实现TextView后面跟随一个高度和宽度固定的ImageView(不要问我为什么不直接用drawableRight,因为宽高不好控制)\n TextView只为1行,即singleLine为true,宽度不定,要求TextView和ImageView站在同一排。" /> <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="16dp" android:orientation="horizontal"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:singleLine="true" android:text="1234567890123456789012345678901234567890123456789012345678901234567890" /> <ImageView android:layout_width="16dp" android:layout_height="16dp" android:src="@drawable/ic_global_list_lable_groupon" /> </LinearLayout> </LinearLayout>
Linearlayout里面的weight其实很好用,但是有朋友可能会想着,为什么只给TextView加weight属性,为什么不给ImageView加。weight是权重的意思,给组件加了该属性之后,该组件就会与其他的同级组件比较权重,然后再布局。闲的无聊的可以去试试把ImageView加weight,或者把TextView的weight取消试试效果。
相关文章推荐
- android学习8#--自定义View之view类简单分析
- Android中制作自定义dialog对话框的实例
- Android初级教程使用服务注册广播接收者监听手机解锁屏变化
- Android初级教程使用服务注册广播接收者监听手机解锁屏变化
- Android Studio实现Service AIDL
- android 获取手机参数整理
- Android-Fragment详解【占坑中】
- Mac 配置Android 终端环境变量
- Android-Bitmap详解【占坑中】
- Android-线程与后台服务【占坑中】
- Android-Handler机制【占坑中】
- Android-Drawable详解【占坑中】
- Android-View的绘制流程【占坑中】
- android 获取手机设备相关信息
- setBackgrounResource内部做了神马?!
- Android SurfaceView 黑屏问题
- 开始第一个Android应用程序
- Android应用程序框架——智能指针(二)
- nineoldandroid 详细使用并且实现drawerlayout侧滑动画
- 利用android-Ultra-Pull-To-Refresh做的下拉刷新,支持viewpager等view完美嵌套