android-percent-support-extend, 用于 android % 支持的扩展库( Google百分比布局库的扩展)

分享于 

12分钟阅读

GitHub

  繁體 雙語
a extends lib for android-percent-support
  • 源代码名称:android-percent-support-extend
  • 源代码网址:http://www.github.com/hongyangAndroid/android-percent-support-extend
  • android-percent-support-extend源代码文档
  • android-percent-support-extend源代码下载
  • Git URL:
    git://www.github.com/hongyangAndroid/android-percent-support-extend.git
    Git Clone代码到本地:
    git clone http://www.github.com/hongyangAndroid/android-percent-support-extend
    Subversion代码到本地:
    $ svn co --depth empty http://www.github.com/hongyangAndroid/android-percent-support-extend
    Checked out revision 1.
    $ cd repo
    $ svn up trunk
    
    android-percent-support-extend
    • 添加了 PercentLinearLayout
    • 支持TextView、Button、EditText的textSize
    • 支持ScrollView内部为Linearlayout
    compile 'com.zhy:percent-support-extends:1.1.1'

    添加了 PercentLinearLayout

    app:layout_heightPercent="50%w"
    app:layout_marginPercent="15%w"
    app:layout_marginBottomPercent="20%h"

    支持通过app:layout_textsizepercent设置textview(button,editText)的textSize

     <TextViewapp:layout_textSizePercent="3%h"/>
    app:layout_maxWidthPercent
    app:layout_maxHeightPercent
    app:layout_minWidthPercent
    app:layout_minWidthPercent
    app:layout_paddingBottomPercent="8%w"
    app:layout_paddingLeftPercent="2%w"
    app:layout_paddingRightPercent="4%w"
    app:layout_paddingTopPercent="6%w"
    <ImageView//...
     app:layout_heightPercent="30%sh"app:layout_widthPercent="30%sh"/>

    Android Studio

    dependencies {
    //...
     compile 'com.zhy:percent-support-extends:1.0.7'
    }
    com.zhy.android.percent.support.PercentLinearLayout
    com.zhy.android.percent.support.PercentRelativeLayout
    com.zhy.android.percent.support.PercentFrameLayout

    ###支持的属性:

    • layout_heightPercent
    • layout_widthPercent
    • layout_marginBottomPercent
    • layout_marginEndPercent
    • layout_marginLeftPercent
    • layout_marginPercent
    • layout_marginRightPercent
    • layout_marginStartPercent
    • layout_marginTopPercent
    • layout_textSizePercent
    • layout_maxWidthPercent
    • layout_maxHeightPercent
    • layout_minWidthPercent
    • layout_minHeightPercent
    • layout_paddingPercent
    • layout_paddingTopPercent
    • layout_paddingBottomPercent
    • layout_paddingLeftPercent
    • layout_paddingRightPercent

    对于值可以取:10%w,10%,10%,10% sw,

    演示 1 [基本用法,主要测试w,h后缀 ]

    xml:

    <?xml version="1.0" encoding="utf-8"?>
    <com.zhy.android.percent.support.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"android:orientation="vertical">
     <com.zhy.android.percent.support.PercentFrameLayout
     android:layout_width="0dp"android:layout_height="0dp"android:layout_gravity="center"android:background="#ff44aacc"app:layout_heightPercent="50%w"app:layout_widthPercent="50%w">
     <com.zhy.android.percent.support.PercentFrameLayout
     android:layout_width="0dp"android:layout_height="0dp"android:layout_gravity="center"android:background="#ffcc5ec7"app:layout_heightPercent="50%w"app:layout_widthPercent="50%w">
     <TextViewandroid:layout_width="match_parent"android:layout_height="match_parent"android:layout_gravity="center"android:background="#ff7ecc16"android:gravity="center"android:text="margin 15% of w"app:layout_marginPercent="15%w"/>
     </com.zhy.android.percent.support.PercentFrameLayout>
     </com.zhy.android.percent.support.PercentFrameLayout>
     <TextViewandroid:layout_width="0dp"android:layout_height="0dp"android:layout_gravity="bottom|right"android:background="#44ff0000"android:gravity="center"android:text="15%w,15%w"app:layout_heightPercent="15%w"app:layout_marginPercent="5%w"app:layout_widthPercent="15%w"/>
    </com.zhy.android.percent.support.PercentFrameLayout>
    演示 2 [基本用法,主要测试w,h后缀 ]

    xml:

    <?xml version="1.0" encoding="utf-8"?>
    <com.zhy.android.percent.support.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">
     <TextViewandroid:id="@+id/id_test"android:layout_width="0dp"android:layout_height="0dp"android:layout_gravity="left|top"android:background="#44ff0000"android:gravity="center"android:onClick="test1"android:text="width:30%,height:20%"app:layout_heightPercent="20%"app:layout_widthPercent="30%"/>
     <TextViewandroid:layout_width="0dp"android:layout_height="0dp"android:layout_gravity="right|top"android:background="#4400ff00"android:gravity="center"android:text="width:70%,height:20%"app:layout_heightPercent="20%"app:layout_widthPercent="70%"/>
     <TextViewandroid:layout_width="0dp"android:layout_height="0dp"android:layout_gravity="bottom"android:background="#770000ff"android:gravity="center"android:text="width:100%,height:10%"app:layout_heightPercent="10%"app:layout_widthPercent="100%"/>
     <ImageViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_gravity="center"android:scaleType="centerCrop"android:src="@drawable/tangyan"app:layout_heightPercent="50%h"app:layout_widthPercent="50%w"/>
     <TextViewandroid:layout_width="0dp"android:layout_height="0dp"app:layout_heightPercent="10%h"app:layout_widthPercent="10%h"android:text="10%h,10%h"android:gravity="center"android:layout_gravity="bottom|right"android:background="#44ff0000"app:layout_marginBottomPercent="20%h"app:layout_marginRightPercent="10%"/>
    </com.zhy.android.percent.support.PercentFrameLayout>
    演示 3 [测试textSize、ScrollView ]

    xml:

    <?xml version="1.0" encoding="utf-8"?>
    <ScrollViewxmlns: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.zhy.android.percent.support.PercentLinearLayout
     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="wrap_content"android:orientation="vertical">
     <TextViewandroid:layout_width="0dp"android:layout_height="0dp"android:background="#ff44aacc"android:gravity="center"android:text="width:60%,height:5%,ts:3%"android:textColor="#ffffff"app:layout_heightPercent="5%"app:layout_marginBottomPercent="5%"app:layout_textSizePercent="3%"app:layout_widthPercent="60%"/>
     <TextViewandroid:layout_width="0dp"android:layout_height="0dp"android:background="#ff4400cc"android:gravity="center"android:text="width:70%,height:10%"android:textColor="#ffffff"app:layout_heightPercent="10%"app:layout_marginBottomPercent="5%"app:layout_widthPercent="70%"/>
     <TextViewandroid:layout_width="0dp"android:layout_height="0dp"android:background="#ff44aacc"android:gravity="center"android:text="w:80%,h:15%,textSize:5%"android:textColor="#ffffff"app:layout_heightPercent="15%"app:layout_marginBottomPercent="5%"app:layout_textSizePercent="5%"app:layout_widthPercent="80%"/>
     <TextViewandroid:layout_width="0dp"android:layout_height="0dp"android:background="#ff4400cc"android:gravity="center"android:text="width:90%,height:5%"android:textColor="#ffffff"app:layout_heightPercent="20%"app:layout_marginBottomPercent="5%"app:layout_widthPercent="90%"/>
     <TextViewandroid:layout_width="match_parent"android:layout_height="0dp"android:background="#ff44aacc"android:gravity="center"android:text="width:100%,height:25%"android:textColor="#ffffff"app:layout_heightPercent="25%"app:layout_marginBottomPercent="5%"/>
     <TextViewandroid:layout_width="match_parent"android:layout_height="0dp"android:background="#ff44aacc"android:gravity="center"android:text="width:100%,height:30%"android:textColor="#ffffff"app:layout_heightPercent="30%"app:layout_marginBottomPercent="5%"/>
     </com.zhy.android.percent.support.PercentLinearLayout>
    </ScrollView>
    演示 4 [参照屏幕的宽或者高进行布局 ]

    星期日的thx

    <?xml version="1.0" encoding="utf-8"?>
    <com.zhy.android.percent.support.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">
     <TextViewandroid:id="@+id/id_test"android:layout_width="0dp"android:layout_height="0dp"android:layout_gravity="left|top"android:background="#44ff0000"android:gravity="center"android:onClick="test1"android:text="width:30%sw,height:20%sh"app:layout_heightPercent="20%sh"app:layout_widthPercent="30%sw"/>
     <TextViewandroid:layout_width="0dp"android:layout_height="0dp"android:layout_gravity="right|top"android:background="#4400ff00"android:gravity="center"android:text="width:70%sw,height:20%sh"app:layout_heightPercent="20%sh"app:layout_widthPercent="70%sw"/>
     <TextViewandroid:layout_width="0dp"android:layout_height="0dp"android:layout_gravity="bottom"android:background="#770000ff"android:gravity="center"android:text="width:100%,height:10%sw"app:layout_heightPercent="10%sw"app:layout_widthPercent="100%"/>
     <ImageViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_gravity="center"android:scaleType="centerCrop"android:src="@drawable/tangyan"app:layout_heightPercent="30%sh"app:layout_widthPercent="30%sh"/>
     <TextViewandroid:layout_width="0dp"android:layout_height="0dp"app:layout_heightPercent="10%sh"app:layout_widthPercent="10%sh"android:text="10%sh,10%sh"android:gravity="center"android:layout_gravity="bottom|right"android:background="#44ff0000"app:layout_marginBottomPercent="15%sw"app:layout_marginRightPercent="10%sw"/>
    </com.zhy.android.percent.support.PercentFrameLayout>

    Android支持库示例

    ext  SUP  Extend  Extends  
    相关文章