标题:Android百分比布局初探

依赖库:——com.android.support:percent

实现原理:

在这个包里面有两个新的容器类 1 PercentRelativeLayout
2 PercentFrameLayout

在此看来,这两个类很显然是继承自 FrameLayout RelativeLayout 两个容器类。

新的容器有了一些设置百分比的属性,下面我们来了解一下:
  • layout_widthPercent
设置控件宽度为父容器的宽的百分比
  • layout_heightPercent
设置控件高度为父容器的高的百分比
  • layout_marginPercent
  • layout_marginLeftPercent
设置控件与左边控件的距离为父容器的宽度的百分比
  • layout_marginTopPercent
设置控件与上方控件的距离为父容器的高度的百分比
  • layout_marginRightPercent
设置控件与右边控件的距离为父容器的宽度的百分比
  • layout_marginBottomPercent
设置控件与下方控件的距离为父容器的高度的百分比
  • layout_marginStartPercent
与上面的说明类似
  • layout_marginEndPercent
与上面的说明类似

从命名的方式我们可以知道,原来用某些具体单位(如 dp )的设置现在都可以用百分比的方式进行设置了,例如设置控件的宽度 layout_width 原来我们是这样玩的 android:layout_width="match_parent" 现在用了百分比的属性之后呢,可以这样玩了 app:layout_widthPercent="50%" ,这里的百分比是相对于父容器而言的。

官方文档地址: https://juliengenoud.github.io/android-percent-support-lib-sample/
官网代码:
1.
PercentFrameLayout
      
        


2. PercentRelativeLayout
                                   


效果:



更多相关文章

  1. android EditText控件如何禁止输入内容
  2. Android控件开发之一----TextView
  3. Android 滚动控件 之 省市区
  4. Android - 基础控件
  5. android自定义按钮控件样式
  6. Android 控件之ProgressBar进度条
  7. android 悬浮控件-仿360手机助手应用详情页
  8. android控件的属性
  9. Android——ListView控件(Android Studio)

随机推荐

  1. Android: Android Property System
  2. android - 确认订单页面【仿】京东App
  3. android gif播放
  4. Android中3D gallary的实现
  5. android里的service和content provider简
  6. android clipPath切割画布
  7. How to resign the Android APK
  8. 调用Android其它Context的Activity
  9. Android问题集锦_FAQ
  10. Android(安卓)8.0、9.0之后的权限以及适