Android横竖屏切换View设置不同尺寸或等比例缩放的自定义View的onMeasure解决方案(2)
附录文章1以xml布局文件方式实现了一个view在横竖屏切换时候的大小尺寸缩放,实现这种需求,也可以使用自定义View的onMeasure方法实现。比如,写一个自定义的ScaleRelativeLayout相对布局:
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <zhangphil.scale.ScaleRelativeLayout android:id="@+id/scale_relative_layout" android:layout_width="0dp" android:layout_height="0dp" android:layout_centerInParent="true" android:background="@android:color/holo_red_light"></zhangphil.scale.ScaleRelativeLayout> </RelativeLayout>
注意在Avtivity中定义configChanges属性:
android:configChanges="orientation|layoutDirection|screenSize"
代码运行结果:
竖屏:
横屏:
附录:
1,《Android横竖屏切换View设置不同尺寸或等比例缩放的XML解决方案》链接地址:http://blog.csdn.net/zhangphil/article/details/73275311
低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。
持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。
转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。
- 上一篇
分享个自己Python爬虫时的浏览器标识库
本人使用的Python3版本,python2未做测试 如有问题很可能出在 toObj函数上toObj函数具体参考:https://stackoverflow.com/questions/1305532/convert-Python-dict-to-object UserAgent.py class toObj(object): def __init__(self, d): for a, b in d.items(): if isinstance(b, (list, tuple)): setattr(self, a, [toObj(x) if isinstance( x, dict) else x for x in b]) else: setattr(self, a, toObj(b) if isinstance(b, dict) else b) ''' Android 设备 ''' Android = toObj({ "Xiaomi": { "Id": "Xiaomi", "Name": "小米手机", "UserAgent": "Mozilla/5.0 (Linux; U; Andr...
- 下一篇
Android系统shell中的clear命令实现
之前一直不太清楚,当我们在shell命令行输入很多命令,会在屏幕上输出一些信息,为什么一执行clear这个命令以后,所有的信息就没了呢? 现在终于搞明白了,找到了clear命令的源代码clear.c 源码如下: #include <stdio.h> int clear_main(int argc, char **argv) { /* This prints the clear screen and move cursor to top-left corner control * characters for VT100 terminals. This means it will not work on * non-VT100 compliant terminals, namely Windows' cmd.exe, but should * work on anything unix-y. */ fputs("\x1b[2J\x1b[H", stdout); return 0; } 震惊了!!!就两行代码!!!这里面稀奇古怪的字符串重定向到stdout(标准输出)是什么东西...
相关文章
文章评论
共有0条评论来说两句吧...
文章二维码
点击排行
推荐阅读
最新文章
- CentOS关闭SELinux安全模块
- SpringBoot2整合Redis,开启缓存,提高访问速度
- Windows10,CentOS7,CentOS8安装Nodejs环境
- Red5直播服务器,属于Java语言的直播服务器
- CentOS6,CentOS7官方镜像安装Oracle11G
- Springboot2将连接池hikari替换为druid,体验最强大的数据库连接池
- CentOS7编译安装Gcc9.2.0,解决mysql等软件编译问题
- SpringBoot2整合Thymeleaf,官方推荐html解决方案
- CentOS7安装Docker,走上虚拟化容器引擎之路
- Jdk安装(Linux,MacOS,Windows),包含三大操作系统的最全安装