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

Android百分比布局支持库 com.android.support:percent

2015-07-26 12:37 489 查看
要想在Android中使用百分比进行布局,首先要导入library.  com.android.support:percent使用方法介绍:百分比控件布局分为两种:PercentFrameLayout   和   PercentRelativeLayout顾名思义都是继承了FrameLayou和RelativeLayout从源码中可以看出,百分比类库支持的属性有如下这些<?xml version="1.0" encoding="utf-8"?><resources><declare-styleable name="PercentLayout_Layout"><attr name="layout_widthPercent" format="fraction"/><attr name="layout_heightPercent" format="fraction"/><attr name="layout_marginPercent" format="fraction"/><attr name="layout_marginLeftPercent" format="fraction"/><attr name="layout_marginTopPercent" format="fraction"/><attr name="layout_marginRightPercent" format="fraction"/><attr name="layout_marginBottomPercent" format="fraction"/><attr name="layout_marginStartPercent" format="fraction"/><attr name="layout_marginEndPercent" format="fraction"/></declare-styleable></resources>使用方法举例:<android.support.percent.PercentRelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"xmlns:tools="http://schemas.android.com/tools"android:layout_width="match_parent"xmlns:app="http://schemas.android.com/apk/res-auto"android:layout_height="match_parent" ><Viewandroid:layout_width="0dp"android:layout_height="0dp"app:layout_widthPercent="50%"app:layout_heightPercent="50%"android:background="#FF4C4B"android:text="@string/hello_world" /></android.support.percent.PercentRelativeLayout>首先要引入 
xmlns:app="http://schemas.android.com/apk/res-auto"
然后在想要使用百分比的控件中使用上述属性进行编写
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息