Android横竖屏切换View设置不同尺寸或等比例缩放的自定义View的onMeasure解决方案(2)...
生活随笔
收集整理的這篇文章主要介紹了
Android横竖屏切换View设置不同尺寸或等比例缩放的自定义View的onMeasure解决方案(2)...
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
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.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"
代碼運行結果:
豎屏:
橫屏:
附錄:
1,《Android橫豎屏切換View設置不同尺寸或等比例縮放的XML解決方案》鏈接地址:http://blog.csdn.net/zhangphil/article/details/73275311?
附錄文章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.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"
代碼運行結果:
豎屏:
橫屏:
附錄:
1,《Android橫豎屏切換View設置不同尺寸或等比例縮放的XML解決方案》鏈接地址:http://blog.csdn.net/zhangphil/article/details/73275311?
總結
以上是生活随笔為你收集整理的Android横竖屏切换View设置不同尺寸或等比例缩放的自定义View的onMeasure解决方案(2)...的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: linux用户及权限详解(2017042
- 下一篇: 分页导航的实现方法