android Percent百分比布局库

android5.0以上新加了宽高可按百分比配置的布局,需要导入资源库percent包,以android studio为标准:

 1.在build.gradle里导入库:

dependencies {
 
    compile 'com.android.support:percent:23.2.0'
}

注意:我第一次加这段代码的时候,这段下面画了红线说明 有错误,只要点击左边红色的小灯泡,再选第一条就可以解决,

2.现在可以用了 这个库有三个主要的 布局分别是:PercentFrameLayout,PercentRelativeLayout,PercentLinearLayout,分别对应我们常用的三种布局:

<?xml version="1.0" encoding="utf-8"?>
<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"
    android:id="@+id/rl"
    >

    <com.touchdemo.view.MTextView
        android:id="@+id/text"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#fff000"
        android:gravity="center"
        app:layout_heightPercent="20%"
        app:layout_widthPercent="30%"
        />
  
</android.support.percent.PercentRelativeLayout>
以PercentRelativrLayout为例,只有包裹在其中控件才能使用百分比的属性,app:layout_heightPercent=""用百分比表示view高,

app:layout_heightPercent=""用百分比表示view宽,

还有一些其他 可以用的属性比如:

layout_marginPercent=""用百分比表示View之间的距离

layout_marginTopPercent=""用百分比表示View顶部的距离

······



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值