android 百分比布局

为了解决Android开发中常见的布局适配问题,Android团队推出了百分比支持库,它继承自RelativeLayout和FrameLayout,并新增了百分比相关的属性设置,如宽度、高度及边距等,使开发者能够更灵活地进行响应式布局设计。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

为了更好的与碎片化战斗,android团队终于推出百分比支持库

(sample下载地址:https://github.com/JulienGenoud/android-percent-support-lib-sample)

这个库是非常容易使用的,因为它就如同 RelativeLayout 和 FrameLayout 一样我们都熟悉,只是有一些额外的功能。


在gradle中添加依赖:

compile 'com.android.support:percent:23.0.0'


这个库提供了:

  • 两种布局供大家使用: 
    PercentRelativeLayoutPercentFrameLayout,通过名字就可以看出,这是继承自FrameLayoutRelativeLayout两个容器类;

  • 支持的属性有:

layout_widthPercentlayout_heightPercent、 
layout_marginPercentlayout_marginLeftPercent、 
layout_marginTopPercentlayout_marginRightPercent、 
layout_marginBottomPercentlayout_marginStartPercentlayout_marginEndPercent

简单的使用举例:

<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
        app:layout_widthPercent="25%"
        android:layout_height="100dp"
        app:layout_marginLeftPercent="5%"
        android:background="#ff0000" />
</android.support.percent.PercentRelativeLayout>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值