百分比布局的基本用法

compile 'com.zhy:percent-support-extends:1.0.1'
studio直接添加上方代码就可以直接添加百分比布局的依赖库
主要提供三个类分别是:<pre style="font-family: 宋体; font-size: 9.6pt;"><span style="color: rgb(0, 0, 128); "><strong><span style="background-color: rgb(228, 228, 255);">1.PercentLinearLayout</span></strong></span><pre style="color: rgb(0, 0, 128); font-size: 9.6pt; font-weight: bold; font-family: 宋体; background-color: rgb(255, 255, 255);"><span style="background-color: rgb(228, 228, 255);">2.Percent</span><span style="font-size: 9.6pt; background-color: rgb(228, 228, 255);">FrameLayout</span>
3.PercentRelativeLayout
基本使用方法是
<com.zhy.android.percent.support.PercentRelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/activity_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"><pre name="code" class="html"><TextView
                android:layout_width="0dp"
                android:layout_height="0dp"
                android:background="#FFFF00"
                android:gravity="center"
                android:text="Hello World!"
                app:layout_heightPercent="20%"
                app:layout_widthPercent="70%" />
</com.zhy.android.percent.support.PercentRelativeLayout>

//如果想要实现ScrollView的嵌套
<pre name="code" class="html"><?xml version="1.0" encoding="utf-8"?>
<com.zhy.android.percent.support.PercentRelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/activity_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin">

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <com.zhy.android.percent.support.PercentLinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">

            <TextView
                android:layout_width="0dp"
                android:layout_height="0dp"
                android:background="#FFFF00"
                android:gravity="center"
                android:text="Hello World!"
                app:layout_heightPercent="20%"
                app:layout_widthPercent="70%" />

            <TextView
                android:layout_width="0dp"
                android:layout_height="0dp"
                android:background="#FFFF00"
                android:gravity="center"
                android:text="Hello World!"
                app:layout_heightPercent="20%"
                app:layout_widthPercent="70%" />

            <TextView
                android:layout_width="0dp"
                android:layout_height="0dp"
                android:background="#FFFF00"
                android:gravity="center"
                android:text="Hello World!"
                app:layout_heightPercent="20%"
                app:layout_widthPercent="70%" />

            <TextView
                android:layout_width="0dp"
                android:layout_height="0dp"
                android:background="#FFFF00"
                android:gravity="center"
                android:text="Hello World!"
                app:layout_heightPercent="20%"
                app:layout_widthPercent="70%" />

            <TextView
                android:layout_width="0dp"
                android:layout_height="0dp"
                android:background="#FFFF00"
                android:gravity="center"
                android:text="Hello World!"
                app:layout_heightPercent="20%"
                app:layout_widthPercent="70%" />

            <TextView
                android:layout_width="0dp"
                android:layout_height="0dp"
                android:background="#FFFF00"
                android:gravity="center"
                android:text="Hello World!"
                app:layout_heightPercent="20%"
                app:layout_widthPercent="70%" />
        </com.zhy.android.percent.support.PercentLinearLayout>
    </ScrollView>
</com.zhy.android.percent.support.PercentRelativeLayout>
//他支持的属性有:
layout_widthPercentlayout_heightPercent
layout_marginPercentlayout_marginLeftPercent
layout_marginTopPercentlayout_marginRightPercent
layout_marginBottomPercentlayout_marginStartPercentlayout_marginEndPercent


版权声明:本文为qq_36136898原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。