您的位置:首页 > 移动开发 > Android开发

android 百分比布局(percentLayout),妈妈再也不用担心适配问题了

2015-09-21 16:04 861 查看
今天事情比较少,没事做就瞎看看,尽然发现android尽然能够像web一样支持百分比布局了,实在是激动人心(以后面试谁再问我适配的问题,我他妈一定要打死他),下面看看如何实现一个百分比布局的页面。

首先添加支持:Project Structure 面板添加:com.android.support:percent:22.2.0



依赖添加好之后可以在build.grade中看见:

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


到这里已经就可以了,是不是超级简单。

下面看下代码:

<?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">

    <TextView
        android:gravity="center"
        android:text="80%"
        android:background="@android:color/holo_green_dark"
        app:layout_widthPercent="80%"
        android:layout_height="0dp"
        android:layout_width="0dp"
        app:layout_heightPercent="30%" />

</android.support.percent.PercentRelativeLayout>


看下效果:



非常简单,但是也很实用。

目前好像只有relativelayout 和framelayout 支持百分比,linearlayout暂时还没有,不过linearlayout有weight属性,不怕!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: