Android 布局开发之百分比布局、弹性布局

1.百分比布局
很简单,超级简单。引用之后就可以使用了。

compile 'com.android.support:percent:23+'

git地址:
https://github.com/JulienGenoud/android-percent-support-lib-sample.git

注意:使用的时候,百分比布局只对他包含的一级有用。就是直属子布局有用。上代码:

<?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"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
<com.google.android.flexbox.FlexboxLayout
    xmlns:fle="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_heightPercent="80%"
    app:layout_widthPercent="80%"
    android:background="@color/colorAccent"
    app:flexWrap="wrap"
    app:alignItems="flex_start"
    app:alignContent="flex_start" >
        <android.support.percent.PercentFrameLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            >
                <TextView
                    android:layout_width="0dp"
                    android:text="aaaasdfsadfasdfsa"
                    app:layout_heightPercent="20%"
                    app:layout_widthPercent="20%"
                    android:layout_height="0dp" />



        </android.support.percent.PercentFrameLayout>

        <android.support.percent.PercentFrameLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            >
                <TextView
                    android:layout_width="0dp"
                    android:text="aaaasdfsadfasdfsa"
                    app:layout_heightPercent="20%"
                    app:layout_widthPercent="20%"
                    android:layout_height="0dp" />

        </android.support.percent.PercentFrameLayout>
</com.google.android.flexbox.FlexboxLayout>
</android.support.percent.PercentFrameLayout>

也就是说只能对她的直属下一级起作用。

2.弹性布局:

compile 'com.google.android:flexbox:0.1.3'

git:
https://github.com/google/flexbox-layout.git

posted @ 2016-06-11 03:03  有点理想的码农  阅读(281)  评论(0)    收藏  举报