安卓百分比布局

来源:互联网 发布:淘宝如何开天猫店 编辑:程序博客网 时间:2024/06/05 04:04

一、导入(最新详见https://github.com/hongyangAndroid/android-percent-support-extend)

compile 'com.zhy:percent-support-extends:1.1.1'
二、属性(以PercentLinearLayout为例,另外还支持PercentFrameLayout,PercentRelativeLayout以及嵌套ScrollView的PercentLinearLayout)

###支持的属性 :

  • 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%h , 10% , 10%sw , 10%sh

一看就明白怎么用了大笑

<?xml version="1.0" encoding="utf-8"?><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="match_parent"    android:orientation="vertical">    <!--    后缀:    h:父控件高度    w:父控件宽度    sh:屏幕高度    sw:屏幕宽度    不加后缀:    1.这个一般是长方形的    app:layout_heightPercent="50%"//父控件高度50%    app:layout_widthPercent="50%"//父控件宽度50%    2.这个是正方形的    app:layout_heightPercent="50%h"    app:layout_widthPercent="50%h"    3.    topbottom为父控件高度的5%    leftright为父控件宽度的5%    app:layout_marginPercent="5%"    4.字体(父控件高度的5%)    app:layout_textSizePercent="5%"    -->    <TextView        android:id="@+id/test1"        android:layout_width="0dp"        android:layout_height="0dp"        android:layout_gravity="left|top"        android:background="#ff7ecc16"        android:gravity="center"        android:onClick="test1"        android:text="百分比布局"        app:layout_heightPercent="50%w"        app:layout_widthPercent="50%h"        app:layout_marginBottomPercent="10%sh"        app:layout_marginEndPercent="10%sw"        app:layout_marginLeftPercent="10%"        app:layout_marginRightPercent="10%"        app:layout_marginStartPercent="10%"        app:layout_marginTopPercent="10%"        app:layout_marginPercent="5%"        app:layout_textSizePercent="5%"        /></com.zhy.android.percent.support.PercentLinearLayout>


原创粉丝点击