1. 程式人生 > >android百分比佈局PercentRelativeLayout

android百分比佈局PercentRelativeLayout

此佈局可以實現按照螢幕比例配置控制元件所佔百分比大小進行適配,並且不受手機橫豎屏影響

下面展示佈局樣式

PercentRelativeLayout

PercentRelativeLayout Complex

操作:

1、加入依賴包

dependencies {
    compile 'com.android.support:percent:25.3.0'
}
2、佈局中使用
<android.support.percent.PercentRelativeLayout
    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"> <View android:id="@+id/top_left" android:layout_width="0dp" android:layout_height="0dp" android:layout_alignParentTop="true" android:background="#ff44aacc" app
:layout_heightPercent="20%" app:layout_widthPercent="70%" /> <View android:id="@+id/top_right" android:layout_width="0dp" android:layout_height="0dp" android:layout_alignParentTop="true" android:layout_toRightOf="@+id/top_left" android:background
="#ffe40000" app:layout_heightPercent="20%" app:layout_widthPercent="30%" /> <View android:id="@+id/bottom" android:layout_width="match_parent" android:layout_height="0dp" android:layout_below="@+id/top_left" android:background="#ff00ff22" app:layout_heightPercent="80%" /> </android.support.percent.PercentRelativeLayout>
<com.juliengenoud.percentsamples.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">
     <View
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:background="#ff44aacc"
        app:layout_heightPercent="10%"
        app:layout_widthPercent="60%"/>

    <View
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:background="#ff4400cc"
        app:layout_heightPercent="10%"
        app:layout_widthPercent="70%"/>
</com.juliengenoud.percentsamples.PercentLinearLayout>
github專案地址:https://github.com/JulienGenoud/android-percent-support-lib-sample

相關推薦

android百分比佈局PercentRelativeLayout

此佈局可以實現按照螢幕比例配置控制元件所佔百分比大小進行適配,並且不受手機橫豎屏影響 下面展示佈局樣式 操作: 1、加入依賴包 dependencies { compile 'com.a

android 百分比佈局percentFrameLayout,percentRelativeLayout的使用

這種佈局方式是google新新增的一種佈局,需要引入安卓的support相容包,這個包大家都很清楚,一般android的新特效新功能都會在support包中。 我們知道。在安卓的佈局中,只有LinearLayout才支援設定權重weight來按比例劃分控制元件的大小,其

Android 百分比佈局+ScrollView

主要分為PercentRelativeLayout,和 PercentFrameLayout PercentRelativeLayout 一、新增依賴 compile 'com.android.support:percent:24.0.0' 二、XML中

百分比佈局PercentRelativeLayout

1.新增依賴compile 'com.android.support:percent:25.3.1'2.直接上程式碼<?xml version="1.0" encoding="utf-8"?> <android.support.percent.Percent

the Percentage Layout of Android (安卓的百分比佈局

不用wrap_content.match_parent來指定 控制元件的大小, 1.在app/bulid.gradle檔案的dependencies中新增 compile 'com.android.support:percent:24.2.1(注意在新增檔案之後要同步一下) 2.修改佈局檔案xml檔案中

Android 適配(百分比佈局 GridView+ListView 項佈局適配)

百分比佈局 參考鴻洋大神的百分比佈局擴充套件,詳細請看這裡 CSDN:https://blog.csdn.net/lmj623565791/article/details/46767825 github:https://github.com/hongyangAndroid/andro

Android Studio3.1.2在專案的build.gradle中新增百分比佈局庫的依賴問題

一、問題        第一行程式碼Android的作者在使用百分比佈局的時候是在build.gradle中新增如下的百分比佈局庫依賴。 開啟app/build.gradle檔案,在dependencies閉包中新增如下內容:  de

Android適配之百分比佈局

一概述 安卓開發過程中一直比較無賴適配的問題,感到比較迷茫,一般的手機開發佈局只是做到簡單的適配,有的時候我們覺得網頁的適配為什麼簡單,其實有了解過的小盆友知道,網頁的介面使用百分比計算的,那麼這樣的

Android ConstraintLayout百分比佈局-適配終結者(基本適配所有機型)

對於Android開發者來講,適配始終是個大問題,在小米手機上面是一個樣,在oppo上面是一個樣,真是讓人惱火。 現在講一下筆者最近遇到的問題,公司專案需求,一顆樹,樹有很有枝椏,枝椏上面要掛紅包,這需求是真坑爹,精度要求特別高,這肯定不能使用DP適配了,最開始想自己根據螢

一種利用百分比佈局適配所有android手機螢幕解析度的方法

場景1、團隊裡面,UI設計師往往只提供以一個標準解析度來設計的UI設計稿,用於Android、iOS、H5三端。2、Android手機解析度眾多,如何讓UI在不同解析度的手機上面能有相同的效果?解決方案在網上看到有一種解決方案是按照螢幕解析度根據基準解析度來等比縮放,經過實際

Android百分比布局成功導入及簡單使用

16px layout wid 就是 height per ont 簡單 app 最近學習第一行代碼第二版這本書,裏面有介紹百分比布局的使用,經過一番摸索,終於是成功導入了百分比布局 就是這樣,appcompat是25.3.1,那麽百分比布局percent也是2

Android線性佈局和相對佈局的詳解和區別

一、線性佈局(LinearLayout) 線性佈局:線性佈局是我們在開發中最常見的佈局方式之一,線性佈局可以分為水平線性佈局和垂直線性佈局這兩種佈局方式 線性佈局的屬性(決定佈局中元素的位置和佈局): android:layout_gravity ( 是本元素相對於父元素的

Android約束佈局ConstraintLayout示例

ConstraintLayout 約束佈局由 2016 年 Google I/O 推出。扁平式的佈局方式,無任何巢狀,減少佈局的層級,優化渲染效能。從支援力度而言,將成為主流佈局樣式,完全代替其他佈局。 佈局示例: <?xml version="1.0" encoding="utf-8

Android佈局ConstraintLayout解析

轉載自鴻洋大神的部落格 一、概述 ConstraintLayout出現有一段時間了,不過一直沒有特別去關注,也多多少少看了一些文字介紹,多數都是對使用視覺化佈局拖拽,個人對拖拽一直不看好,直到前段時間看到該文: 解析ConstraintLayout的效能優勢 非常詳盡的介紹

android排版(佈局)

幀佈局 就是覆蓋(覆蓋之前的控制元件) FrameLayout 還有一種方式就是用x y軸去調位置 不過比較麻煩  <TextView         android:id="@

android studio佈局顯示異常

design一直看不了 發現佈局右上角有個感嘆號 點開發現提示failed to instantiate one or more classes,百度一下搜到的csdn一個答案https://blog.csdn.net/newlai913/article/details/68939791&

android LinearLayout佈局巢狀覆蓋問題

在做android  UI佈局時,用了LinearLayout巢狀,發現效果並不如我預料一般 查了下資料,說是要設定layout_weight屬性 資料說得不是很清楚,也沒仔細看,就去弄,結果越弄越混亂。 於是靜下心來,自己寫xml測試,發現如下。 我用eclipse開發,

Android FlexboxLayout佈局屬性詳解

FlexboxLayout是Google I/O 大會上開源的一個佈局控制元件,使得 Android 裡的佈局能像 CSS中的Flexible屬性一樣能擁有同樣強大的功能。FlexboxLayout 可以理解為高階的 LinearLayout ,因為這兩個佈局都將其子檢視按序排列

H5 邊框:帶border的百分比佈局

響應式Web設計經常需要我們通過百分比設定元件寬度。如果我們不考慮邊框,那麼很容易就可以實現,但如果你給每一列以及總寬度都採用百分比設定,那這個時候固定的邊框大小就會出來搗亂。下面我們將看到一組方法去解決這個問題,你會學到如何建立一個流式佈局,而不用擔心額外的邊框以及內邊距。 假設我們需要一個五列的佈局

Android佈局中的view存成圖片

新浪部落格轉載地址 http://blog.sina.com.cn/s/blog_6854b8350101qila.html android可以將佈局中的view存成圖片。這個問題雖然不常見,但是有還是會應用到。來看下面一段程式碼 View view = getLayoutInfla