All Projects → thunderpunch → Stretchview

thunderpunch / Stretchview

Licence: mit
a stretchable view which is used together with CoordinatorLayout

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to Stretchview

WellBehavedFX
Composable event handlers and skin scaffolding for JavaFX controls.
Stars: ✭ 52 (+173.68%)
Mutual labels:  behavior
Unity-Visual-Behavior-Tree
Reactive Visual Scripting Behavior Tree Tool for Unity 2018.x+
Stars: ✭ 36 (+89.47%)
Mutual labels:  behavior
Aecor
Pure functional event sourcing runtime
Stars: ✭ 299 (+1473.68%)
Mutual labels:  behavior
AmapLike
【高仿】高德地图 包含定位、搜索、路径规划等功能 map bottomsheet
Stars: ✭ 51 (+168.42%)
Mutual labels:  behavior
LiteRefresh
Nested scrolling UI library for Android based on CoordinatorLayout. Pull-to-refresh and pull-to-load-more are supported.
Stars: ✭ 37 (+94.74%)
Mutual labels:  behavior
NestedScrollingDemo
😋😋😋A good app for understanding android nested scrolling
Stars: ✭ 98 (+415.79%)
Mutual labels:  behavior
LuaKit
Lua核心工具包,包含对面向对象,组件系统(灵活的绑定解绑模式),mvc分模块加载,事件分发系统等常用模式的封装。同时提供打印,内存泄漏检测,性能分析等常用工具类。
Stars: ✭ 112 (+489.47%)
Mutual labels:  behavior
Doctrinebehaviors
Doctrine2 behavior traits
Stars: ✭ 782 (+4015.79%)
Mutual labels:  behavior
MaterialDesignSample
Android transition元素共享动画、CoordinatorLayout、AppBarLayout、FloatingActionButton、BottomSheet、SnackBar、自定义behavior实现动画效果。
Stars: ✭ 28 (+47.37%)
Mutual labels:  behavior
Crazydaily
[开源项目] 一款程序员日常放松的App,基于Material Design + MVP-Clean + Weex + Flutter + RxJava2 + Retrofit + Dagger2 + Glide + Okhttp + MTRVA + BRVAH + 炫酷控件 + 炫酷动画
Stars: ✭ 294 (+1447.37%)
Mutual labels:  behavior
behaiv-java
User Behavior Prediction for everyone
Stars: ✭ 12 (-36.84%)
Mutual labels:  behavior
android-materialButton-behavior
Android Material Button(Extended FAB) Behavior on RecyclerView
Stars: ✭ 25 (+31.58%)
Mutual labels:  behavior
yii2-db
Database extensions for Yii 2.0 Framework 📦
Stars: ✭ 19 (+0%)
Mutual labels:  behavior
behavior-trait
Allows handling events via inline declared methods, which can be added by traits
Stars: ✭ 18 (-5.26%)
Mutual labels:  behavior
Ucmainpagerdemo
Use custom behavior to implement UC Browser 's MainPager UI
Stars: ✭ 398 (+1994.74%)
Mutual labels:  behavior
beehive
A flexible, modern, header-only implementation of behavior trees
Stars: ✭ 37 (+94.74%)
Mutual labels:  behavior
Westworld-Style-Behavior-Pad-Interface
UPDATE 20210705: Adding ZeroMQ functions in to allow full-duplex comms with deep parts of the hosts' cognitive processes, and expose speech recognition background processes, visual processes, etc. ORIGINAL DESCRIPTION >>>This is a working version of the iconic Behavior Pad "Rose Graph" Interface that the Westworld Techs use to set Host Behaviora…
Stars: ✭ 25 (+31.58%)
Mutual labels:  behavior
Materialdesignsamples
Material Design 系列控件samples,讲了Material Design 系列新控件的使用方法和一些场景示例,使用详情请看对应博客,持续更新中...
Stars: ✭ 900 (+4636.84%)
Mutual labels:  behavior
Learn Coordinatorlayout Behavior
CoordinatorLayout 自定义Behavior 高仿美团商家详情界面 实现页面内容复杂联动效果
Stars: ✭ 527 (+2673.68%)
Mutual labels:  behavior
behave-restful
BDD Framework to Test REST Services and APIs
Stars: ✭ 47 (+147.37%)
Mutual labels:  behavior

StretchView

a stretchable view which is used together with CoordinatorLayout

the effect is shown as below

bottom right
vertical horizontal

Usage

  1. 在布局中添加StretchView,并确保它是CoordinatorLayout的直系子视图。

  2. 在StretchView内部添加一个子视图作为内容视图,且只能添加一个。

  3. 添加一个NestedScrollingChild作为嵌套滑动发起方,同时绑定自定义的TranslationBehavior。

    <android.support.design.widget.CoordinatorLayout
    	android:layout_width="match_parent"
    	android:layout_height="match_parent"
    	tools:context="com.thunderpunch.stretchview.MainActivity">
    
    	<com.thunderpunch.stretchview.view.StretchView
        	android:id="@+id/sv"
        	style="@style/AppTheme.AppBarOverlay"
        	android:layout_width="match_parent"
        	android:layout_height="wrap_content"
        	app:stretchFactor="0.4"
        	android:background="@color/colorPrimary"
        	app:direction="bottom">
    
        	<!-- StretchView can host only one direct child -->
    
    	</com.thunderpunch.stretchview.view.StretchView>
      
    	<android.support.v4.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="com.thunderpunch.stretchview.behavior.TranslationBehavior">
      
    	</android.support.v4.widget.NestedScrollView>
    </android.support.design.widget.CoordinatorLayout>
    
  4. (可选)添加嵌套滑动过程中的回调

    final StretchView sv = (StretchView) findViewById(R.id.sv);
    sv.setOnStretchListener(new StretchView.OnStretchListener() {
        @Override
        public void onTranslation(int trans) {
            if (sv.getDirection() == StretchView.BOTTOM || sv.getDirection() == StretchView.RIGHT) {
                trans = -trans;
            }
            if (trans > 0) {
                if (trans >= sv.getContentSpace()) {
                    //拉伸状态
                   
                } else {
                    //非拉伸状态
                   
                }
            }
        }
    });
    

XML attributes

name format description
stretchFactor float 拉伸比例 ( 拉伸比例 x StretchView直系子视图在拉伸方向的边长 = 最大拉伸量 )
direction enum 初始隐藏方位 支持left,right,bottom,当 direction = left 或 right 时,StretchView将响应横向的嵌套滑动,当direction = bottom 时,响应纵向嵌套滑动

Customizations

  • 自定义childview的绘制方式

    如果不设置,默认使用DefaultDrawHelper,绘制效果见bottom.gif

    public void setDrawHelper(StretchDrawHelper drawHelper) {
        this.mDrawHelper = drawHelper;
    }
    
    public static abstract class StretchDrawHelper {
    
        protected StretchView v;
    
        public StretchDrawHelper(StretchView v) {
            this.v = v;
        }
    
        /**
         * @return 是否支持布局方向 {@link StretchView.DirectionOption}
         */
        public abstract boolean supportDirection(@DirectionOption int direction);
    
        /**
         * 绘制childview前的回调
         *
         * @return 绘制childview用到的变换矩阵
         */
        public abstract Matrix draw(Canvas canvas, int translation);
    
        /**
         * chidlview绘制完成后的回调
         */
        public void onDrawComplete(Canvas canvas, int translation) {
    
        }
    }
    
    @Override
    protected void dispatchDraw(Canvas canvas) {
        final View child = getChildAt(0);
        if (child == null || child.getVisibility() == GONE) return;
        if (mDrawHelper == null) {
            mDrawHelper = new DefaultDrawHelper(this);
        }
        if (mDrawHelper.supportDirection(mDirection)) {
            canvas.save();
            canvas.concat(mDrawHelper.draw(canvas, mTranslation));
            drawChild(canvas, child, getDrawingTime());
            canvas.restore();
            mDrawHelper.onDrawComplete(canvas, mTranslation);
        } else {
            super.dispatchDraw(canvas);
        }
    }
    

License

MIT License

Copyright (c) 2017 thunderpunch

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].