android自定義控件-懸浮控件 StickyNavLayout
StickyNavLayout 懸浮控件
該項目是在一個開源項目的基礎上修改的
原項目地址:https://github.com/hongyangAndroid/Android-StickyNavLayout
修改如下:
1.在原基礎上支持對內容listview等控件空布局的滑動支持 2.修改當剛剛懸浮的時候抬起手觸發onItemClick事件的bug 3.修改手快速滑動的時候觸發onItemClick事件的bug 4.增加一些自定義屬性,后文有介紹 5.增加是否處于懸浮的回調接口,和滑動到懸浮狀態的比例:0~1 ;1~0 之間變化的數字 6.增加對GridView-GridViewWithHeaderAndFooterFragment(支持header和footer的GridView) 7.修改其它一些bug 8.將原文遷移到AS中 9.將此項目發布到JCenter,方便大家的使用哦GridViewWithHeaderAndFooterFragment
地址:https://github.com/liaohuqiu/android-GridViewWithHeaderAndFooter
聲明
本項目純屬開源,只是為了更好的提高Android的開發技術,小寶貝們~~~~~
效果圖
自定義屬性
<resources>
<declare-styleable name="StickNavLayout">
<!--默認是否懸停tab-->
<attr name="isStickNav" format="boolean" />
<!--距離懸浮的位置-->
<attr name="stickOffset" format="dimension" />
</declare-styleable>
</resources>
使用時的注意事項
注意控件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" 比如:<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
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.support.v7.widget.RecyclerView
android:id="@+id/id_stickynavlayout_innerscrollview"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</FrameLayout>
or
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ScrollView
android:id="@+id/id_stickynavlayout_innerscrollview"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="@string/msg"
android:textSize="20sp" />
</ScrollView>
</LinearLayout>
使用
<com.gxz.library.StickyNavLayout
android:id="@+id/id_stick"
android:layout_width="match_parent"
android:layout_height="match_parent"
stick:isStickNav="true">
<LinearLayout
android:id="@id/id_stickynavlayout_topview"
android:layout_width="match_parent"
android:layout_height="200dp"
android:background="#fee"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:text="top-view"
android:textAllCaps="true"
android:textSize="30sp" />
</LinearLayout>
<com.gxz.PagerSlidingTabStrip
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.support.v4.view.ViewPager
android:id="@id/id_stickynavlayout_viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</com.gxz.library.StickyNavLayout>
Java 代碼使用
相信你可以點一下就知道什么用了 .... 是不是呢?小寶貝~~~!!
接口回調
stickyNavLayout.setOnStickStateChangeListener(new StickyNavLayout.onStickStateChangeListener() {
@Override
public void isStick(boolean isStick) {
}
@Override
public void scrollPercent(float percent) {
}
});
Maven
<dependency>
<groupId>com.gxz.pagerslidingtabstrip</groupId>
<artifactId>library</artifactId>
<version>1.1</version>
<type>jar</type>
<classifier>sources</classifier>
</dependency>
Gradle
compile('com.gxz.stickynavlayout:library:1.0')
Demo
Demo中的導航控件是:PagerSlidingTabStrip
是我一個開源項目:https://github.com/ta893115871/PagerSlidingTabStrip
感謝
感謝我的同事的幫助
https://github.com/DukeLee1989
本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!