标题: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中实现循环滚动
  2. Android常见知识点
  3. 设置TextView文字居中
  4. Android(安卓)调用相册 拍照 实现系统控件缩放 切割图片
  5. android 加边框
  6. 转: Android(安卓)layout xml总结
  7. Android布局技巧大全(持续更新..........)
  8. 一张图看遍LinearLayout的所有特有属性
  9. Android(安卓)Market的 Loading效果

随机推荐

  1. 吐血推荐一些有用的网址1
  2. android实现EditText的多行输入框
  3. android 提升性能总结
  4. webrtc——web与android,android间通信
  5. android实用测试方法之Monkey与MonkeyRun
  6. android下发送中文短消息
  7. android在游戏中一直保持屏幕高亮
  8. Android开机自启动程序
  9. android fastboot 使用
  10. Android--Activity的四种启动模式和onNew