Material Design之CollapsingToolbarLayout 相關(guān)屬性和方法介紹


廢話不多說? 先看看這東西的效果圖。

一張沒圖片的和一張有圖片的,圖片太丑別怪我。還是把圖換了吧,怕你們打我。


開始無知的我還以為是監(jiān)聽 onTouchListener 根據(jù)滑動(dòng)的距離和位置來改變顯示效果來實(shí)現(xiàn)的。

唉,今天無意中看到這個(gè)?CollapsingToolbarLayout 。

百度了一下,大致了解點(diǎn)。

不過東西還是要到 官方的地盤去看看原版的。

所以就去android.support.design.widget這個(gè)包下找到“元兇”CollapsingToolbarLayout了。

然后順便揪出了這些東西分享給大家。

1.android.support.design:collapsedTitleGravity

e.g. ?app:collapsedTitleGravity="left"

Specifies how the title should be positioned when collapsed.

指定在折疊之后標(biāo)題放置的位置

2.android.support.design:collapsedTitleTextAppearance

e.g. ?app:collapsedTitleTextAppearance="@color/colorPrimary"

The text appearance of the CollapsingToolbarLayouts title when it is fully 'collapsed'

Must be a reference to another resource, in the form "@[+][package:]type:name" or to a theme attribute in the form "?[package:][type:]name".

在折疊的時(shí)候標(biāo)題文字的外觀必須引用另一個(gè)資源 ,以“@[+][包:]類型:名稱”或 主題屬性形式”?(包:)類型:名稱”。

2.1 ?android.support.design:expandedTitleTextAppearance

和上面的一樣 ?在展開的時(shí)候標(biāo)題文字的外觀

3.android.support.design:contentScrim

e.g. ?app:contentScrim="#ff5252"

The drawable to use as a scrim on top of the CollapsingToolbarLayouts content when it has been scrolled sufficiently off screen.

指定在折疊之后的背景色

4.android.support.design:expandedTitleGravity

e.g. ?app:expandedTitleGravity="left|bottom"

Specifies how the title should be positioned when expanded.

在展開的時(shí)候 標(biāo)題放置的位置

5.android.support.design:expandedTitleMargin

e.g. ?app:expandedTitleMargin="16dp"

Specifies extra space on the start, top, end and bottom sides of the the expanded title text.

設(shè)置邊界距離 和 textview等效果一樣

6.android.support.design:expandedTitleMarginBottom底部的margin距離

7.android.support.design:expandedTitleMarginEnd右邊的margin距離

8.android.support.design:expandedTitleMarginStart左邊的margin距離

9.android.support.design:statusBarScrim

e.g. ?app:statusBarScrim="#123456"

The drawable to use as a scrim for the status bar content when the CollapsingToolbarLayout has been scrolled sufficiently off screen.

在折疊的時(shí)候 狀態(tài)欄的背景顏色

10. android.support.design:title

e.g. ?app:title="Title"

The title to show when titleEnabled is set to true.

如果標(biāo)題可用的話 顯示的標(biāo)題文字

11.android.support.design:titleEnabled

e.g. ?app:titleEnabled="true"

Whether the CollapsingToolbarLayout should draw its own shrinking/growing title.

是否顯示標(biāo)題

12.android.support.design:toolbarId

e.g. ?app:toolbarId="@id/toolbar"

The id of the primary Toolbar child that you wish to use for the purpose of collapsing.

在折疊的時(shí)候 顯示的toolbar的id

13.app:layout_scrollFlags="scroll|exitUntilCollapsed"

scroll - 想滾動(dòng)就必須設(shè)置這個(gè)。

enterAlways - 實(shí)現(xiàn)quick return效果, 當(dāng)向下移動(dòng)時(shí),立即顯示View(比如Toolbar)。

exitUntilCollapsed - 向上滾動(dòng)時(shí)收縮View,但可以固定Toolbar一直在上面。

enterAlwaysCollapsed - 當(dāng)你的View已經(jīng)設(shè)置minHeight屬性又使用此標(biāo)志時(shí),你的View只能以最小高度進(jìn)入,只有當(dāng)滾動(dòng)視圖到達(dá)頂部時(shí)才擴(kuò)大到完整高度。

測試的xml文件,可以copy進(jìn)去測試就行。

一個(gè)問題NestedScrollView高度加上頂部AppBarLayout高度沒超過屏幕高低滑動(dòng)有問題(只能在AppBarLayout范圍內(nèi)才能滑動(dòng));

這里沒換MarkDown? 代碼不好弄, ?代碼傳送門

里面的有個(gè)imageview,注釋已經(jīng)寫的很清楚了。

當(dāng)然 里面的toolbar 你們還可以設(shè)置其他的屬性

然后里面的NestedScrollView這貨。

它和scrollview 基本上一樣 ?但是它支持嵌套滾動(dòng) ?嵌套滾動(dòng)默認(rèn)是啟用的。

還有一個(gè)屬性,不過蛋疼的是這屬性要全手打,沒提示不知道怎么破。

android:fillViewportlike: android:fillViewport="true"

Defines whether the scrollview should stretch its content to fill the viewport.

定義滾動(dòng)視圖是否應(yīng)該伸展它的內(nèi)容來填補(bǔ)視窗。


然后就是這個(gè)類的一些方法:

draw(Canvas canvas)

Manually render this view (and all of its children) to the given Canvas.

渲染指定的畫布

//獲取新的布局參數(shù)

generateLayoutParams(AttributeSet attrs)

Returns a new set of layout parameters based on the supplied attributes set.

//設(shè)置和獲取折疊之后的標(biāo)題位置

getCollapsedTitleGravity();setCollapsedTitleGravity(int gravity)

//獲取和設(shè)置折疊之后的背景

getContentScrim()

setContentScrim(Drawable drawable)

setContentScrimColor(int color)

setContentScrimResource(int resId)

//設(shè)置和獲取展開的標(biāo)題位置

setExpandedTitleGravity(int gravity)

getExpandedTitleGravity()

//獲取和設(shè)置狀態(tài)欄的顏色

getStatusBarScrim()

setStatusBarScrim(Drawable drawable)

setStatusBarScrimColor(int color)

setStatusBarScrimResource(int resId)

//設(shè)置和獲取標(biāo)題

setTitle(CharSequence title)

getTitle()

//獲取和設(shè)置標(biāo)題文字是否顯示

isTitleEnabled()

setTitleEnabled(boolean enabled)

//設(shè)置折疊之后的標(biāo)題文字外觀

setCollapsedTitleTextAppearance(int resId)

//設(shè)置折疊之后的標(biāo)題文字顏色

setCollapsedTitleTextColor(int color)

//設(shè)置展開的標(biāo)題文字顏色

setExpandedTitleColor(int color)

//設(shè)置展開的標(biāo)題文字外觀

setExpandedTitleTextAppearance(int resId)

如果你喜歡我寫的,請(qǐng)關(guān)注我。

歡迎留言拍磚。

我的博客:http://blog.csdn.net/lxk_1993

友情鏈接;

自定義View實(shí)戰(zhàn)(一) 汽車速度儀表盤

自定義View實(shí)戰(zhàn)(二) ?QQ健康水滴形加載

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容