天天看點

DragSlopLayout

ragSlopLayout

項目位址:Rukey7/DragSlopLayout 

DragSlopLayout

簡介:A UI library for Android

更多:作者   提 Bug   官網   

标簽:

DragSlopLayout
DragSlopLayout

一個輔助開發的 UI 庫,适用于某些特殊場景,如固定範圍拖拽、動畫、模糊效果等。

Screenshot

Drag 模式,可以和 ViewPager 關聯

DragSlopLayout

Animate 模式,同樣可以和 ViewPager 關聯(自定義動畫無關聯效果)

DragSlopLayout

Blur 模糊效果,包括局部模糊和全圖模糊

DragSlopLayout

外部拖拽,在螢幕上垂直滑動就可對視圖進行拖拽,能夠設定主視圖滑動折疊

DragSlopLayout

Gradle

庫依賴

allprojects {
        repositories {
            ...
            maven { url 'https://jitpack.io' }
        }
    }
           

因為模糊庫比較大,如果你需要使用模糊效果則依賴的版本{lastest-version}後面加上'-blur',不需要則不用加

compile 'com.github.Rukey7:DragSlopLayout:{lastest-version}-blur'
           

使用模糊庫需要設定對應的配置

android {
    defaultConfig {
        renderscriptTargetApi 23
        renderscriptSupportModeEnabled true
    }
}
           

Usage

屬性

name format description
mode enum drag、animate 或者 drag_outside, 預設為 drag
fix_height dimension drag 模式收縮的高度, 預設為 0
max_height dimension drag 模式展開的高度,預設為布局高度的 2/3
collapse_parallax float 折疊系數,效果同 CollapsingToolbarLayout,預設為 1

布局

<com.dl7.drag.DragSlopLayout
    android:id="@+id/drag_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/black"
    app:fix_height="80dp"
    app:mode="drag">
        <!-- Content View -->
        <android.support.v4.view.ViewPager
        android:id="@+id/vp_photo"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>

        <!-- Drag View -->
        <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">
        // ......
    </LinearLayout>
    // ......
</com.dl7.drag.DragSlopLayout>
           

如果 Content View 為 ViewPager,通過以下方法來實作關聯效果:

mDragLayout.interactWithViewPager(true);
    // 下面新增的方法會更适用,替換上面舊的方法
    mDragLayout.attachViewPager(ViewPager);
    mDragLayout.detachViewPager();
           

如果 Drag View 包含 ScrollView 或則 NestedScrollView,通過以下方法來實作平滑滾動:

mDragLayout.setAttachScrollView(mSvView);
           

Content View 的模糊效果,這功能是通過模糊預處理再來動态加載的,是以對于 Content View 為 ViewPager 的界面不适用,主要用來模糊固定的背景界面

mDragLayout.setEnableBlur(true);    // 開啟模糊
    mDragLayout.setBlurFull(true);    // 設定全背景模糊,預設為局部模糊
    mDragLayout.updateBlurView();    // 更新模糊背景
           

控制 Drag View 的進入和退出

mDragLayout.scrollInScreen(int duration);    // Drag 模式
    mDragLayout.scrollOutScreen(int duration);    // Drag 模式

    mDragLayout.startInAnim();    // Animate 模式
    mDragLayout.startOutAnim();    // Animate 模式
    mDsLayout.setAnimatorMode(DragSlopLayout.FLIP_Y);    // 設定動畫模式
           

設定拖拽監聽

mDragLayout.setDragPositionListener(new DragSlopLayout.OnDragPositionListener() {
            @Override
            public void onDragPosition(int visibleHeight, float percent, boolean isUp) {
                // TODO
            }
        });
           

Thanks

  • 500px-android-blur
  • AndroidViewAnimations

License

Copyright 2016 Rukey7

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.