android-support-percent的学习使用笔记

在sdk/extras/android/support/percent目录下,有个jar包,仔细发现,这个jar包是支持Percent百分比布局的,所以特别学习了一下,虽然这个包出现了好久,这才注意到。好了进入正题,怎么写个Demo来使用这个jar呢?

1.将工程导入Gradle工程:

从改percent所在的目录可以看到,该工程是eclipse目录下的,所以需要转换一下,转换成gradle工程,然后导入,建议将该目录复制到一个临时的地方,自己修改成Gradle工程module后再进行导入。

注意:虽然该目录下,只有一个jar和attrs文件和AndroidManifest.xml文件,但是如果仅引用jar包,会报错的:提示找不到R.styleable 。XXX文件

或者可以直接下载aar:http://download.csdn.net/detail/zouchengxufei/9560927
之后直接导入即可!

2.代码示例:

主工程引用了上面的aar之后,就可以引用该包下的相关类资源了,该包下有以下资源:

PercentFrameLayout
PercentFrameLayout.LayoutParams
PercentLayoutHelper
PercentLayoutHelper.PercentLayoutInfo
PercentRelativeLayout
PercentRelativeLayout.LayoutParams
可以参考Sdk/docs/reference/android/support/percent/package-summary.html文件查看详情
布局代码示例:

<?xml version="1.0" encoding="utf-8"?>
<android.support.percent.PercentFrameLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/activity_percent"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.example.administrator.testapplication.PercentActivity">

    <ImageView android:src="@drawable/a8g"
      android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:layout_widthPercent="50%"
        app:layout_heightPercent="50%"
        app:layout_marginTopPercent="25%"
        app:layout_marginLeftPercent="25%"

        />
    <View android:background="#333333"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:layout_widthPercent="25%"
        app:layout_marginTopPercent="25%"
        app:layout_marginLeftPercent="75%"
        app:layout_heightPercent="25%"


        />
</android.support.percent.PercentFrameLayout>
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值