Android横竖屏切换View设置不同尺寸或等比例缩放的自定义View的onMeasure解决方案(2)...
生活随笔
收集整理的這篇文章主要介紹了
Android横竖屏切换View设置不同尺寸或等比例缩放的自定义View的onMeasure解决方案(2)...
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
Android橫豎屏切換View設(shè)置不同尺寸或等比例縮放的自定義View的onMeasure解決方案(2)
附錄文章1以xml布局文件方式實(shí)現(xiàn)了一個(gè)view在橫豎屏切換時(shí)候的大小尺寸縮放,實(shí)現(xiàn)這種需求,也可以使用自定義View的onMeasure方法實(shí)現(xiàn)。比如,寫一個(gè)自定義的ScaleRelativeLayout相對(duì)布局:
<?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.ScaleRelativeLayoutandroid: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"
代碼運(yùn)行結(jié)果:
豎屏:
橫屏:
附錄:
1,《Android橫豎屏切換View設(shè)置不同尺寸或等比例縮放的XML解決方案》鏈接地址:http://blog.csdn.net/zhangphil/article/details/73275311?
附錄文章1以xml布局文件方式實(shí)現(xiàn)了一個(gè)view在橫豎屏切換時(shí)候的大小尺寸縮放,實(shí)現(xiàn)這種需求,也可以使用自定義View的onMeasure方法實(shí)現(xiàn)。比如,寫一個(gè)自定義的ScaleRelativeLayout相對(duì)布局:
<?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.ScaleRelativeLayoutandroid: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"
代碼運(yùn)行結(jié)果:
豎屏:
橫屏:
附錄:
1,《Android橫豎屏切換View設(shè)置不同尺寸或等比例縮放的XML解決方案》鏈接地址:http://blog.csdn.net/zhangphil/article/details/73275311?
總結(jié)
以上是生活随笔為你收集整理的Android横竖屏切换View设置不同尺寸或等比例缩放的自定义View的onMeasure解决方案(2)...的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: linux用户及权限详解(2017042
- 下一篇: Android-TextView跑马灯效