android百分比布局PercentRelativeLayout
16lz
2021-01-26
此布局可以实现按照屏幕比例配置控件所占百分比大小进行适配,并且不受手机横竖屏影响
下面展示布局样式
操作:
1、加入依赖包
dependencies { compile 'com.android.support:percent:25.3.0'}2、布局中使用
<android.support.percent.PercentRelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent"> <View android:id="@+id/top_left" android:layout_width="0dp" android:layout_height="0dp" android:layout_alignParentTop="true" android:background="#ff44aacc" app:layout_heightPercent="20%" app:layout_widthPercent="70%" /> <View android:id="@+id/top_right" android:layout_width="0dp" android:layout_height="0dp" android:layout_alignParentTop="true" android:layout_toRightOf="@+id/top_left" android:background="#ffe40000" app:layout_heightPercent="20%" app:layout_widthPercent="30%" /> <View android:id="@+id/bottom" android:layout_width="match_parent" android:layout_height="0dp" android:layout_below="@+id/top_left" android:background="#ff00ff22" app:layout_heightPercent="80%" />android.support.percent.PercentRelativeLayout>
<com.juliengenoud.percentsamples.PercentLinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <View android:layout_width="0dp" android:layout_height="0dp" android:background="#ff44aacc" app:layout_heightPercent="10%" app:layout_widthPercent="60%"/> <View android:layout_width="0dp" android:layout_height="0dp" android:background="#ff4400cc" app:layout_heightPercent="10%" app:layout_widthPercent="70%"/>com.juliengenoud.percentsamples.PercentLinearLayout>github项目地址:https://github.com/JulienGenoud/android-percent-support-lib-sample
更多相关文章
- Android(安卓)快速开发之快速实现“我”界面
- Android信息界面编辑及组合控件的封装
- Android自定义Layout
- android 键盘弹出,布局重绘
- Android:控件布局(单帧布局)FrameLayout
- Android(13)——RecyclerView列表流行控件,Glide图片流行框架
- Android(安卓)ApiDemos示例解析(109):Views->Custom
- 居中总结
- Android在onCreate或者在Fragment的onCreateView中获取控件、屏