android support Percent支持库开发
Android的布局支持百分比的設(shè)置進(jìn)行開(kāi)發(fā),來(lái)學(xué)習(xí)如何去實(shí)現(xiàn)它,不過(guò)看起來(lái)會(huì)像網(wǎng)頁(yè)的設(shè)置,比如寬度的設(shè)置屬性是`layout_widthPercent`。在此之前,我們一般都會(huì)設(shè)置Linearlayout的weight權(quán)重來(lái)實(shí)現(xiàn)布局間的比例大小。
Percent support Library提供了兩個(gè)新的類(lèi):
1.PercentRelativeLayout
2.PercentFrameLayout
?
創(chuàng)建新項(xiàng)目?
創(chuàng)建一個(gè)新的項(xiàng)目來(lái)測(cè)試,修改`build.gradle`,需要引入以下庫(kù)
`applyplugin:'com.android.application'android {compileSdkVersion23buildToolsVersion"23.0.0"defaultConfig {applicationId"com.android.chaowen.percentdemo1"minSdkVersion7targetSdkVersion22versionCode1versionName"1.0"}buildTypes {release {minifyEnabledfalseproguardFilesgetDefaultProguardFile('proguard-android.txt'),'proguard-rules.pro'}}}dependencies {compile fileTree(dir:'libs',include: ['*.jar'])compile'com.android.support:support-annotations:23.0.0'compile'com.android.support:appcompat-v7:23.0.0'compile'com.android.support:design:23.0.0'compile'com.android.support:percent:23.0.0'}創(chuàng)建布局
xmlns:android="http://schemas.android.com/apk/res/android"xmlns:app="http://schemas.android.com/apk/res-auto"xmlns:tools="http://schemas.android.com/tools"android:layout_width="match_parent"android:layout_height="match_parent"tools:context=".MainActivity">android:id="@+id/first"android:background="@color/sa_green_dark"app:layout_heightPercent="50%"app:layout_marginLeftPercent="25%"app:layout_marginTopPercent="25%"app:layout_widthPercent="50%" />android:layout_width="0dp"android:layout_height="32dp"android:layout_alignLeft="@id/first"android:layout_alignStart="@id/first"android:layout_alignRight="@id/first"android:layout_alignEnd="@id/first"android:layout_below="@id/first"android:layout_marginTop="8dp"android:background="@color/light_grey" />比例大小是通過(guò)`heightPercent`和`widthPercent`屬性來(lái)設(shè)置百分比大小值。完全屬于`RelativeLayout`的擴(kuò)展類(lèi),值得一提的是,
不再需要設(shè)置`layout_width`和`layout_height`,注意了,這是新的庫(kù)使用方法,因?yàn)檫@兩個(gè)屬性會(huì)被自動(dòng)加入了。
百度比也可以用于設(shè)置邊距。唯一區(qū)別的只是采取了百分比值。
最后一點(diǎn)需要注意,在第二個(gè)view,并沒(méi)有直接設(shè)置比例的大小,但是它的位置是相對(duì)于第一個(gè)view.
?
轉(zhuǎn)載于:https://www.cnblogs.com/andgoo/p/4781204.html
與50位技術(shù)專(zhuān)家面對(duì)面20年技術(shù)見(jiàn)證,附贈(zèng)技術(shù)全景圖總結(jié)
以上是生活随笔為你收集整理的android support Percent支持库开发的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 4、线程范围内的数据共享之ThreadL
- 下一篇: pat1035. Password (2