您现在的位置是:首页 > 文章详情

Android横竖屏切换View设置不同尺寸或等比例缩放的自定义View的onMeasure解决方案(2)

日期:2017-06-18点击:941
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 

原文链接:https://yq.aliyun.com/articles/615860
关注公众号

低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。

持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。

转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。

文章评论

共有0条评论来说两句吧...

文章二维码

扫描即可查看该文章

点击排行

推荐阅读

最新文章