Android百分比布局初探
16lz
2022-05-14
标题:Android百分比布局初探 依赖库:——com.android.support:percent
实现原理:
在这个包里面有两个新的容器类 1 、 PercentRelativeLayout2 、 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
效果:
更多相关文章
- Android中实现循环滚动
- Android常见知识点
- 设置TextView文字居中
- Android(安卓)调用相册 拍照 实现系统控件缩放 切割图片
- android 加边框
- 转: Android(安卓)layout xml总结
- Android布局技巧大全(持续更新..........)
- 一张图看遍LinearLayout的所有特有属性
- Android(安卓)Market的 Loading效果