android support Percent支持库开发
生活随笔
收集整理的這篇文章主要介紹了
android support Percent支持库开发
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
Android的布局支持百分比的設置進行開發,來學習如何去實現它,不過看起來會像網頁的設置,比如寬度的設置屬性是`layout_widthPercent`。在此之前,我們一般都會設置Linearlayout的weight權重來實現布局間的比例大小。
Percent support Library提供了兩個新的類:
1.PercentRelativeLayout
2.PercentFrameLayout
?
創建新項目?
創建一個新的項目來測試,修改`build.gradle`,需要引入以下庫
`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'}創建布局
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" />比例大小是通過`heightPercent`和`widthPercent`屬性來設置百分比大小值。完全屬于`RelativeLayout`的擴展類,值得一提的是,
不再需要設置`layout_width`和`layout_height`,注意了,這是新的庫使用方法,因為這兩個屬性會被自動加入了。
百度比也可以用于設置邊距。唯一區別的只是采取了百分比值。
最后一點需要注意,在第二個view,并沒有直接設置比例的大小,但是它的位置是相對于第一個view.
?
轉載于:https://www.cnblogs.com/andgoo/p/4781204.html
與50位技術專家面對面20年技術見證,附贈技術全景圖總結
以上是生活随笔為你收集整理的android support Percent支持库开发的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 4、线程范围内的数据共享之ThreadL
- 下一篇: pat1035. Password (2