Android: How to scroll header to top when there is no/limited items in ListView? -


I'm developing an Android app in which I added header visit to the listview. Now I want the header view to display only then It should be done when a user scrolls down the list view. I tried the following, but was not successful in getting the required output.

  • listView.setSelection (1) works well, but only when the size of the data is above the visible area, that is, the ListView scrolls.
  • Android: Scroll URA is giving the required UI output but it is not easy to scroll headers under the list view, i.e. the search bar comes down by shock.

    I need the same behavior even when there is only one item in the list but when the list is limited in the list, the header is always visible.

    Enter image details here

    Any suggestions

    This effect can be easily obtained by a simple move, compile 'com.android.support : be sure to include build.gradle in support-v13: 20.0.0 ' or if you are on eclipse, download the latest support jar file:

    Use the following XML layouts:

      & lt; Android.support.v4.widget.SwipeRefreshLayout xmlns: android = "http://schemas.android com / apk / res / android" Android: Android: Android: layout_width = "match_parent" android: layout_height = "match_parent" Android: ClipChildren = "false" & gt; & Lt; LinearLayout Android: layout_width = "match_parent" Android: layout_height = "match_parent" android: clipChildren = "false" android: orientation = "vertical" & gt; Android: Android: Android: Android: Android: Android: Android: Android: Android: Android: Android: Android: Android: Android: Android: Android: Android: Gravity = "Center" Android: Text = " My hidden search bar "/> & Lt; ListView android: id = "@ android: id / list" Android: layout_width = "match_parent" Android: layout_height = "match_parent" android: text = "@ string / hello_world" /> & Lt; / LinearLayout & gt; & Lt; /android.support.v4.widget.SwipeRefreshLayout>   

    This is your activity s code:

      Public class expands MyActivity activity {@Override Creates Secure Zero (Bundle Saved InstantState) {Super.onCreate (Saved Instantstate); setContentView (R.layout.activity_my); See the last searchBar = findViewById (RID. Searchbar); Final swipefirefresh layout SW = (SwipeRefreshLayout) findViewById (R.id.pullToShowBar); Sw.setColorSchemeColors (Color.TRANSPARENT, COLOR, Color. Visionary, Color. Consultant); sw.setOnRefreshListener (New SwipeRefreshLayout.OnRefreshListener () {@Override public void onRefresh () {sw.setRefreshing (wrong); ViewGroup.MarginLayoutParams layoutAllow = (ViewGroup.MarginLayoutParams) searchBar.getLayoutParams (); LayoutMetchMeter (0, 0, 0, 0); Searchbar.SteelTranspace (LayoutProgram);}}}}}   

    one last piece:

      import android.content.Context; import Android.support.v4.view.ViewCompat; Import android.support.v4.widget.SwipeRefreshLayout; Import android.util.AttributeSet; Import android.widget.AbsListView; Public Class PultoScarchLayut SwitcherFirefresh Layout (Private ExhibitView ML Public, Pulto-SearchBailLayout (reference) {} (publicity);} Pultoarchbarlayout (reference references, AttributeSet attrs) {super (references, attrs);} @ override public boolean canChildScrollUp () {if (mListView == empty) {MListView = (AbsListView) findViewById (android.R.id.list);} if (android.os.build.VERSION.SDK_INT & lt; 14) {Final AbsListView absListView = mListView; Return absListView.getChildCount () & gt; 0 and amp; Amp; (AbsListView.getFirstVisiblePosition () & gt; + + absListView.getChildAt (0) .getTop () & lt; absListView.getPaddingTop ()); } And {return ViewCompat.canScrollVertically (mListView, -1); }}}    

Comments

Popular posts from this blog

Pass DB Connection parameters to a Kettle a.k.a PDI table Input step dynamically from Excel -

multithreading - PhantomJS-Node in a for Loop -

c++ - MATLAB .m file to .mex file using Matlab Compiler -