Android 百分比佈局+ScrollView
阿新 • • 發佈:2019-01-30
主要分為PercentRelativeLayout,和 PercentFrameLayout
PercentRelativeLayout
一、新增依賴
compile 'com.android.support:percent:24.0.0'
二、XML中
<android.support.percent.PercentRelativeLayout
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"
>
...
...
...
</android.support.percent.PercentRelativeLayout>
內部的元件可以通過
app:layout_heightPercent
app:layout_widthPercent
app:layout_marginTopPercent
app:layout_marginLeftPercent
...
...
如:
app:layout_heightPercent="5%"
app:layout_widthPercent="100%"
百分比佈局還可以外層巢狀一個ScrollView 實現上滑下滑
因為百分比佈局的佈局百分比不是按照百分比佈局的大小來設定,而是根據螢幕的大小設定
所以百分比佈局可以設定為高為 wrapContent的
但是注意 ScrollView 只能有一個子佈局
若底部導航欄擋住了一些控制元件,可以在底部加一個space控制元件,這樣就可以讓ScrollView上滑,也增加了螢幕的靈活性。
三、問題
below無效
1 加一個imageView作為分隔線樣式 正好也能實現below了
2 等待一下控制元件載入?
PercentRelativeLayout要設定為MatchParent的寬高
但是,比如一個RecyclerView的Item佈局
我需要的是這個Item佈局以百分比的位置設定,但是父佈局又想WrapContent
該怎麼辦?
待填坑…