写布局代码时的小技巧--
来源:互联网 发布:淘宝客怎么开通条件 编辑:程序博客网 时间:2024/05/22 09:43
1、水平布局,一边文字,一边图片
这种情况,如果利用比例,很有可能会有图片显示不完整的问题,所以最好使用如下View占位的方法:
<LinearLayout android:layout_width="match_parent" android:layout_height="60dp" android:padding="20dp"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="这是左边文字"/> <View android:layout_width="0dp" android:layout_weight="1" android:layout_height="match_parent"/> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/btn_check"/> </LinearLayout>
2、水平布局,两边都是文字,文字长度一边确定,一边不确定
这种情况最好也不要使用比例,主要是因为左右比例自己也很难确定。这时常用的是如下方式:
<LinearLayout android:layout_width="match_parent" android:layout_height="60dp" android:padding="20dp"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="这是左边文字"/> <TextView android:layout_width="0dp" android:layout_weight="1" android:gravity="end" android:layout_height="wrap_content" android:text="这是右边不确定长度文字"/> </LinearLayout>
意思就是除了左边文字所占的宽度位置,其余的宽度位置均为右边Text所有。
3、文字四周有图片
这种情况就不用把文字和图片单独给个控件了,一个TextView就能解决了:
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="这是文字" android:drawableBottom="@drawable/btn_check" android:drawablePadding="10dp"/>
●其中android:drawableBottom属性是指图片相对于文字的位置在在底部,同样drawableLeft表示图片在文字左边,等等。
●其中android:drawablePadding属性是指图片与文字的距离。
4、TextView实现竖排文字
实现竖排文字使用一个TextView的属性就可以了:
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="20sp" android:text="这是竖排文字" android:ems="1" android:lineSpacingExtra="10dp" />
●其中android:ems=“1”属性就是指每行一个文字
●其中android:lineSpacingExtra属性是指文字之间的行间距
5、待更新。。。。
阅读全文
0 0
- 写布局代码时的小技巧--
- 写代码小技巧
- oc写代码的一个小技巧
- 写Java代码的小技巧
- 如何写高效率的AS3代码的小技巧
- oj系统上写代码的一些小技巧
- oj系统上写代码的一些小技巧
- oj系统上写代码的一些小技巧
- 写代码过程中一些优化的小技巧。
- 写代码的技巧
- 写注释的小技巧
- 写程序的小技巧
- 使用GridLayout布局时的一个小技巧(margin)
- 写javascript代码的技巧
- css布局的一个小技巧
- Android布局优化的一些小技巧
- 关于布局的一些小技巧
- 新手学习网页布局的小技巧!
- chrome扩展程序白名单
- 李航第二章课后习题
- GET,POST,PUT,DELETE的区别
- 公众号微信内置地图在ios上不显示问题
- Java导出数据库查询结果为excel和csv的对比
- 写布局代码时的小技巧--
- CHINA TOP国家杯:用电子竞技搭建中国文化走出去的平台
- arcgis server soe文件无法上传到服务管理器manager
- Angular入门-Hero Editor抽丝
- 错误处理(4)—— “{000208D5-0000-0000-C000-000000000046}”的接口的 COM 组件调用 QueryInterface 因以下错误而失败
- 将项目中执行的 SQL 打印到 laravel.log 文件中
- windows GDI编程中关于窗口和视口,逻辑坐标和设备坐标的转换
- better-scroll滑动插件的使用
- iOS 原生网络请求