android 仿360悬浮按钮,StickyNavLayout

StickyNavLayout 悬浮控件

该项目是在一个开源项目的基础上修改的

原项目地址:

https://github.com/hongyangAndroid/Android-StickyNavLayout/

修改如下:

1.在原基础上支持对内容listview等控件空布局的滑动支持

2.修改当刚刚悬浮的时候抬起手触发onItemClick事件的bug

3.修改手快速滑动的时候触发onItemClick事件的bug

4.增加一些自定义属性,后文有介绍

5.增加是否处于悬浮的回调接口,和滑动到悬浮状态的比例:01 ;10 之间变化的数字

6.增加对GridView-GridViewWithHeaderAndFooterFragment(支持header和footer的GridView)

7.修改其它一些bug

8.将原文迁移到AS中

9.将此项目发布到JCenter,方便大家的使用哦

#GridViewWithHeaderAndFooterFragment

https://github.com/liaohuqiu/android-GridViewWithHeaderAndFooter/

#声明

本项目纯属开源,只是为了更好的提高Android的开发技术,小宝贝们~~~~~

效果图

stick_0.gif

stick_1.gif

0ca01005739a1fed4e72f12fa281582f.gif

#自定义属性

#stickOffset 属性细说

现在悬浮是当top区域完全滑动到屏幕外面时,中间的悬浮区域悬浮起来了,如果你有这么一种需求是距离悬浮区域有一定的距离比如(40dp)可以用这个属性,满足需求.

#使用时的注意事项

注意控件id的设置

top区域:id必须为: android:id="@+id/id_stickynavlayout_topview"

悬浮区域:id必须为: android:id="@+id/id_stickynavlayout_indicator"

内容区域:id必须为: android:id="@+id/id_stickynavlayout_viewpager"

内容区域

1.比需为ViewPager或者其子类

2.ViewPager的内容可以是Fragment,如果Fragment想用ListView,RecycleView等需要设置其id为:

android:id="@+id/id_stickynavlayout_innerscrollview"

比如:

xmlns:tools="http://schemas.android.com/tools"

android:layout_width="match_parent"

android:layout_height="match_parent"

tools:context="com.gxz.stickynavlayout.fragments.RecycleViewFragment">

android:id="@+id/id_stickynavlayout_innerscrollview"

android:layout_width="match_parent"

android:layout_height="match_parent"/>

or

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="vertical">

android:id="@+id/id_stickynavlayout_innerscrollview"

android:layout_width="match_parent"

android:layout_height="match_parent">

android:layout_width="match_parent"

android:layout_height="match_parent"

android:text="@string/msg"

android:textSize="20sp" />

#使用

android:id="@+id/id_stick"

android:layout_width="match_parent"

android:layout_height="match_parent"

stick:isStickNav="true">

android:id="@id/id_stickynavlayout_topview"

android:layout_width="match_parent"

android:layout_height="200dp"

android:background="#fee"

android:orientation="vertical">

android:layout_width="match_parent"

android:layout_height="match_parent"

android:gravity="center"

android:text="top-view"

android:textAllCaps="true"

android:textSize="30sp" />

android:id="@+id/id_stickynavlayout_indicator"

android:layout_width="match_parent"

android:layout_height="48dp"

android:textSize="16sp"

pst:pstsDividerColor="@color/colorPrimary"

pst:pstsIndicatorColor="@color/colorPrimary"

pst:pstsIndicatorHeight="5dp"

pst:pstsScaleZoomMax="0"

pst:pstsShouldExpand="false"

pst:pstsTextSelectedColor="#303F9F"

pst:pstsUnderlineColor="@color/colorPrimary" />

android:id="@id/id_stickynavlayout_viewpager"

android:layout_width="match_parent"

android:layout_height="match_parent" />

#TopView(顶部区域大于一屏)

xmlns:cube_ptr="http://schemas.android.com/apk/res-auto"

xmlns:pst="http://schemas.android.com/apk/res-auto"

xmlns:stick="http://schemas.android.com/apk/res-auto"

android:id="@+id/store_house_ptr_frame"

android:layout_width="match_parent"

android:layout_height="match_parent"

cube_ptr:ptr_duration_to_close="300"

cube_ptr:ptr_duration_to_close_header="2000"

cube_ptr:ptr_keep_header_when_refresh="true"

cube_ptr:ptr_pull_to_fresh="false"

cube_ptr:ptr_ratio_of_header_height_to_refresh="1.2"

cube_ptr:ptr_resistance="1.7">

android:id="@+id/id_stick"

android:layout_width="match_parent"

android:layout_height="match_parent"

stick:isStickNav="false">

android:id="@id/id_stickynavlayout_topview"

android:layout_width="match_parent"

android:layout_height="wrap_content">

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:background="#fee"

android:orientation="vertical">

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:gravity="center"

android:text="@string/msg"

android:textAllCaps="true"

android:textSize="20sp" />

android:id="@+id/id_stickynavlayout_indicator"

android:layout_width="match_parent"

android:layout_height="48dp"

android:textSize="16sp"

pst:pstsDividerColor="@color/colorPrimary"

pst:pstsIndicatorColor="@color/colorPrimary"

pst:pstsIndicatorHeight="5dp"

pst:pstsScaleZoomMax="0"

pst:pstsShouldExpand="false"

pst:pstsTextSelectedColor="#303F9F"

pst:pstsUnderlineColor="@color/colorPrimary" />

android:id="@id/id_stickynavlayout_viewpager"

android:layout_width="match_parent"

android:layout_height="match_parent" />

Java 代码使用

相信你可以点一下就知道什么用了 .... 是不是呢?小宝贝~~~!!

#接口回调

stickyNavLayout.setOnStickStateChangeListener(new StickyNavLayout.onStickStateChangeListener() {

@Override

public void isStick(boolean isStick) {

}

@Override

public void scrollPercent(float percent) {

}

});

#Maven

com.gxz.stickynavlayout

library

1.3.1

jar

sources

Gradle

compile 'com.gxz.stickynavlayout:library:1.3.1'

#Demo

Demo中的导航控件是:PagerSlidingTabStrip

是我一个开源项目:

https://github.com/ta893115871/PagerSlidingTabStrip/

#V1.1版本

1.增加如果TopView大于一屏TopView无法显示的问题,比如顶部区域为ScrollView

2.支持顶部区域可以是ScrollView

#V1.2版本

1.修复TOP区域中不支持控件动态GONE/VISIBLE的BUG

使用用法,设置完GONE/VISIBLE后调用updateTopViews();方法

@OnClick(R.id.show)

public void show() {

button1.setVisibility(View.VISIBLE);

// button2.setVisibility(View.VISIBLE);

linearLayoutLayout.setVisibility(View.VISIBLE);

stickyNavLayout.updateTopViews();

}

@OnClick(R.id.hide)

public void hide() {

button1.setVisibility(View.GONE);

// button2.setVisibility(View.GONE);

linearLayoutLayout.setVisibility(View.GONE);

stickyNavLayout.updateTopViews();

}

再次 如果你动态修改了top区域中有关view(比如TextView的文本-这时高度就变了),这是你需要在修改完后重新调用如下方法,更新高度

比如:

textViewMsg.setText(getResources().getString(R.string.msg));

stickyNavLayout.updateTopViews();

从而可以避免topView有空白或者高度不够的问题

2.增加setStickNavAndScrollToNav方法.

该方法的意思是:java代码动态设置悬浮,并自动滚动到悬浮位置(即把top区域滚动上去),详细见demo中的TopOperateActivity

#V1.3版本

修改因1.2版本造成的stickOffset不起作用的问题

#V1.3.1版本

修改stickOffset造成内容区域底部显示不全问题,最近丢三落四的!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值