Android 实现TextView后面跟随一个高度和宽度固定的ImageView
来源:互联网 发布:虚拟机安装哪个mac不卡 编辑:程序博客网 时间:2024/06/18 13:14
安卓实现TextView后面跟随一个高度和宽度固定的ImageView(不要问我为什么不直接用drawableRight,因为宽高不好控制)
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取消试试效果。
3 0
- Android 实现TextView后面跟随一个高度和宽度固定的ImageView
- [CAQ4]ImageView宽度固定,高度自适应的实现方式
- 宽度固定,高度自适应的imageview
- Android 设置ImageView宽度固定,其高度按比例缩放适应
- Android 自定义imageview图片高度固定大小宽度按比例自适应
- Android 自定义imageview 图片宽度固定大小高度按比例自适应
- Android 自定义imageview 图片高度固定大小宽度按比例自适应
- Android 设置ImageView宽度固定,其高度按比例缩放适应
- Android 设置ImageView宽度固定,其高度按比例缩放适应
- android imageview中 scaletype 与 宽度固定高度自适应
- android实现正方形的ImageView、Layout等(即高度适应宽度或者宽度适应高度)
- android 实现正方形的ImageView、Layout等(即高度适应宽度或者宽度适应高度)
- android实现正方形的ImageView、Layout等(即高度适应宽度或者宽度适应高度)
- 宽度固定高度按原图比例适应的ImageView
- android布局时,左侧宽度固定而右侧textview高度变化,怎么9png实现左侧高度与右侧相等?
- 动态设置ImageView的宽度和高度
- 高度和宽度不固定元素水平和垂直居中的实现(父元素高度和宽度固定)(完美解决兼容问题)
- 动态的获取和设置ImageView的宽度和高度
- Git合并分支
- java反射详解
- Android属性之build.prop生成过程分析及各系统初始配置修改
- allegro 群组布线
- C++之模板
- Android 实现TextView后面跟随一个高度和宽度固定的ImageView
- 在桌面版 Ubuntu 中安装 Unity Tweak Tool
- Android Studio背景图插件
- Problem I - Bricks ACM/ICPC Central Europe Regional Contest 2014
- route命令(详细)
- 解决svn造成桌面图标显示问号的问题
- 为什么要学shell脚本编程(多一个技能,多条路,是实现思路)
- 在Eclipse中使用JUnit4进行单元测试(中级篇)
- 使用uploadify3.2.1 formData传递其他参数到后台,JAVA后台获取参数方法