Skip to content

Latest commit

History

21 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

StickHeaderLayout

An Android library supports sticking the navigator on the top when ItemView scrolls. more flexible than 「 github.com/w446108264/StickyHeaderViewPager

To sticks the navigatior on the top can overwriting the View or dispatch events, Why choosing a way which add a header on scrolling view that looks more complex and intrusive? The answer is that is more common, stable and smoothly scrolling.

Art

ArtArtArt

Art

Art

Features

  • API > 11
  • Support RecyclerView, ScrollView, WebView, ListView.
  • Scrolling, with smooth scrolling fling, will not be interrupt when ticking the navigator.
  • Don't need to preset the height value,all is automatic.
  • Support pulltoRefresh

Samples

You can download a sample APK

Gradle Dependency

Users of your library will need add the jitpack.io repository:

allprojects {
repositories {
jcenter()
maven { url "https://jitpack.io" }
}
}

and:

dependencies { compile 'com.github.w446108264:StickHeaderLayout:1.0.3'
}

--

Usage

simple to your proejct

Layout

howerver, StickHeaderLayout must have three childViews,frist childView will scroll with viewpager,second will tick on the top.

 <com.stickheaderlayout.StickHeaderLayout 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=".ListViewSimpleActivity">
<TextViewandroid:layout_width="match_parent"android:layout_height="200dp"android:background="#293"android:gravity="center"android:text="header" />
<TextViewandroid:layout_width="match_parent"android:layout_height="50dp"android:background="#874"android:gravity="center"android:text="listview simple activity" />
<ListViewandroid:id="@+id/v_scroll"android:layout_width="match_parent"android:layout_height="match_parent" />
</com.stickheaderlayout.StickHeaderLayout>

Activity

@OverrideprotectedvoidonCreate(BundlesavedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_listview);
ListViewlv_data = (ListView)findViewById(R.id.v_scroll);
intsize = 100;
String[] stringArray = newString[size];
for (inti = 0; i < size; ++i) {
stringArray[i] = ""+i;
}
ArrayAdapter<String> adapter = newArrayAdapter<>(this, android.R.layout.simple_list_item_1, stringArray);
lv_data.setAdapter(adapter);
}

ViewPager

just like other scrollview when uses StickHeaderLayout on ViewPager.in page which want to stick on the top when scrolling, the page must appoint a view PlaceHoderHeaderLayout

<?xml version="1.0" encoding="utf-8"?>
<com.stickheaderlayout.StickHeaderLayout xmlns:android="http://schemas.android.com/apk/res/android"xmlns:tools="http://schemas.android.com/tools"android:id="@+id/shl_root"android:layout_width="match_parent"android:layout_height="match_parent"tools:context=".ListViewSimpleActivity">
<TextViewandroid:layout_width="match_parent"android:layout_height="200dp"android:background="#293"android:gravity="center"android:text="header" />
<LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"android:orientation="vertical">
<TextViewandroid:layout_width="match_parent"android:layout_height="50dp"android:background="#874"android:gravity="center"android:text="viewpager simple activity" />
<LinearLayoutandroid:id="@+id/ly_tab"android:layout_width="match_parent"android:layout_height="wrap_content"android:orientation="horizontal">
<TextViewandroid:id="@+id/tv_tab1"android:layout_width="match_parent"android:layout_height="30dp"android:gravity="center"android:text="Recycler"android:background="#124020"android:textColor="@android:color/black"android:layout_weight="1"/>
... </LinearLayout>
</LinearLayout>
<android.support.v4.view.ViewPager
android:id="@+id/v_scroll"android:layout_width="match_parent"android:layout_height="match_parent" />
</com.stickheaderlayout.StickHeaderLayout>

PullToRefresh

easy to add a pulltorefresh header,such as 「 android-Ultra-Pull-To-Refresh

 <?xml version="1.0" encoding="utf-8"?>
<in.srain.cube.views.ptr.PtrClassicFrameLayout xmlns:android="http://schemas.android.com/apk/res/android"xmlns:app="http://schemas.android.com/apk/res-auto"xmlns:cube_ptr="http://schemas.android.com/apk/res-auto"xmlns:tools="http://schemas.android.com/tools"android:id="@+id/rotate_header_list_view_frame"android:layout_width="match_parent"android:layout_height="match_parent"cube_ptr:ptr_duration_to_close="200"cube_ptr:ptr_duration_to_close_header="1000"cube_ptr:ptr_keep_header_when_refresh="false"cube_ptr:ptr_pull_to_fresh="false"cube_ptr:ptr_ratio_of_header_height_to_refresh="1"cube_ptr:ptr_resistance="1.1">
<com.stickheaderlayout.StickHeaderLayout
android:id="@+id/shl_root"android:layout_width="match_parent"android:layout_height="match_parent"app:scrollViewId="@+id/v_scroll"tools:context=".ListViewSimpleActivity">
<TextViewandroid:layout_width="match_parent"android:layout_height="200dp"android:background="#293"android:gravity="center"android:text="header" />
<TextViewandroid:layout_width="match_parent"android:layout_height="50dp"android:background="#874"android:gravity="center"android:text="listview simple activity" />
<RelativeLayoutandroid:layout_width="match_parent"android:layout_height="match_parent">
<ListViewandroid:id="@+id/v_scroll"android:layout_width="match_parent"android:layout_height="match_parent" />
<Buttonandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_alignParentBottom="true"android:layout_centerHorizontal="true"android:layout_marginBottom="80dp"android:text="TEST" />
</RelativeLayout>
</com.stickheaderlayout.StickHeaderLayout>
</in.srain.cube.views.ptr.PtrClassicFrameLayout>

Contact & Help

Please fell free to contact me if there is any problem when using the library.

About

An Android library supports sticking the navigator on the top when ItemView scrolls.

Resources

Stars

138 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages