android布局滑動(dòng)到頂端懸浮,吸頂

ok 首先我們來(lái)看看是不是咱們想要的效果!免得浪費(fèi)大家時(shí)間

效果圖.gif

這里采用CoordinatorLayout+AppBarLayout配合使用

再來(lái)看一下布局結(jié)構(gòu)


布局結(jié)構(gòu).jpg
現(xiàn)在要使用的話則Copy一下代碼稍作修改即可
<android.support.design.widget.CoordinatorLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <android.support.design.widget.AppBarLayout
            android:id="@+id/appbar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@color/color_two">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="center"
                boy:layout_scrollFlags="scroll|exitUntilCollapsed"
                android:orientation="vertical">


                <ImageView
                    android:layout_width="match_parent"
                    android:layout_height="@dimen/dp_200"
                    android:src="@mipmap/testimage" />

                <ImageView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:src="@mipmap/ic_launcher" />

            </LinearLayout>

            <LinearLayout
                android:id="@+id/ll_topview"
                android:layout_width="match_parent"
                android:layout_height="116dp"
                android:gravity="right"
                android:background="@color/color_three"
                android:orientation="vertical">

                <View
                    android:layout_width="match_parent"
                    android:background="@color/color_two"
                    android:layout_height="66dp"/>

                <Button
                    android:id="@+id/btn_screen"
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent"
                    android:text="篩選" />

            </LinearLayout>

        </android.support.design.widget.AppBarLayout>

        <android.support.v7.widget.RecyclerView
            android:id="@+id/reclerview"
            android:layout_width="match_parent"
            boy:layout_behavior="@string/appbar_scrolling_view_behavior"
            boy:layout_scrollFlags="scroll"
            android:layout_height="match_parent">
        </android.support.v7.widget.RecyclerView>

    </android.support.design.widget.CoordinatorLayout>

這里需要注意一點(diǎn)的是

1.design這個(gè)包版本需要在26以上,不然有點(diǎn)卡頓,加速度有點(diǎn)問(wèn)題

2.如果我們懸浮模塊以上的這部分布局很長(zhǎng),超過(guò)了一屏,那么我們需要給AppBar加一個(gè)判斷,如下

private int mI;

appbar.addOnOffsetChangedListener(new AppBarLayout.OnOffsetChangedListener() {
            @Override
            public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) {
                //為0時(shí)表示AppBarLayout完全顯示
                mI = verticalOffset;
                refreshLayout.setEnableRefresh(mI >= 0);
            }
        });
//外層我是用的一個(gè)刷新控件 SmartRefreshLayout
//https://github.com/scwang90/SmartRefreshLayout/blob/master/art/md_property.md

好了這樣就大功告成了,這次是不是清楚了

回手掏 鬼刀一開(kāi)看不見(jiàn) 走位走位 哈哈 老鐵心心來(lái)一個(gè)

demo下載鏈接:點(diǎn)擊這里就ok,ps里面融云的包沒(méi)刪不用管

最后編輯于
?著作權(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),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

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

  • ok 首先我們來(lái)看看是不是咱們想要的效果!免得浪費(fèi)大家時(shí)間 這篇沒(méi)勁,我另外一篇詳細(xì)一點(diǎn)可以看一下 哈哈 麻煩老...
    Android丶boy閱讀 2,825評(píng)論 0 33
  • Android 自定義View的各種姿勢(shì)1 Activity的顯示之ViewRootImpl詳解 Activity...
    passiontim閱讀 179,351評(píng)論 25 708
  • 用兩張圖告訴你,為什么你的 App 會(huì)卡頓? - Android - 掘金 Cover 有什么料? 從這篇文章中你...
    hw1212閱讀 14,118評(píng)論 2 59
  • CoordinatorLayout與滾動(dòng)的處理 CoordinatorLayout實(shí)現(xiàn)了多種Material De...
    cxm11閱讀 6,840評(píng)論 1 15
  • ng-model 指令ng-model 指令 綁定 HTML 元素 到應(yīng)用程序數(shù)據(jù)。ng-model 指令也可以:...
    壬萬(wàn)er閱讀 975評(píng)論 0 2

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