此布局可以实现按照屏幕比例配置控件所占百分比大小进行适配,并且不受手机横竖屏影响

下面展示布局样式



操作:

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

更多相关文章

  1. Android(安卓)快速开发之快速实现“我”界面
  2. Android信息界面编辑及组合控件的封装
  3. Android自定义Layout
  4. android 键盘弹出,布局重绘
  5. Android:控件布局(单帧布局)FrameLayout
  6. Android(13)——RecyclerView列表流行控件,Glide图片流行框架
  7. Android(安卓)ApiDemos示例解析(109):Views->Custom
  8. 居中总结
  9. Android在onCreate或者在Fragment的onCreateView中获取控件、屏

随机推荐

  1. android录屏直播:VLC通过rtsp协议播放andr
  2. Android平台12月广告浏览份额51.6% 超越i
  3. [转] Android最佳实践之响应灵敏性
  4. 谷歌被曝即便禁止定位仍在后台收集用户位
  5. Android中AsyncTask的用法
  6. [Android 高级教程] Android条码扫描
  7. 關於 Android 下的自動化測試
  8. 一步步做Android增强型图片浏览器
  9. Android 蓝牙对等通信初探
  10. Android(安卓)View/ViewRoot泄漏但Activi