Overscroll header/footer for ScrollView? - android

ListView has this nice feature where you can set an overscroll header or footer. ScrollView, unfortunately, has no such thing. Does anyone know of a way to put together something that works like a ScrollView with an overscroll header/footer?

My best guess is you might be able to accomplish this with a similar approach as pull-to-refresh for lists is implemented on Android devices: you basically stretch a view at the top of (probably actually above - same for a 'footer', but then below) the ScrollView to fake an overscroll effect.
For some ideas on this, have a look at this pull-to-refresh implementation. It dynamically adjusts the padding of a header view in the list to simulate it being overscrolled when 'pulling'.

Can't you put your ScrollView inside a RelativeLayout, which will also contain the header and footer? Something like this:
<RelativeLayout ...>
<TextView
android:id="#+id/header"
android:alignParentTop="true"/>
<ScrollView
android:id="#+id/scroller"
android:layout_below="#id/header"
android:layout_height="fill_parent"/>
<TextView
android:id="#+id/footer"
android:layout_below="#id/scroller"
android:alignParentBottom="true"/>
</RelativeLayout>
In this question ( Can we use a ScrollView inside a LinearLayout? ), someone showed how to put a ScrollView inside a LinearLayout. It should be the same.

Related

Enable scroll for scrollview not listview

I have a ListView inside of a ScrollView - but my issue is that I don't want the Listview to scroll, instead I want the listview to be fully expanded and just scroll the ScrollView up and down to see the items of the ListView. Can someone recoment a solution?
Here is my layout:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal"
>
<ListView
android:id="#+id/user_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:divider="#null"
android:visibility="gone" />
</ScrollView>
P.S. I know that this is bad practice but I need this thing anyway
set this property in your scrollview android:fillViewport="true" it will work
two scrolling views cannot be inside one another.
Follow the following link:
ListView inside ScrollView is not scrolling on Android
You can consider this. But the ListView's height must be hard coded and it does recycling which slightly deviates from your requirement. But ListView without recycling, as you mentioned, is not a good practice. So try to achieve the thing with recycling as described in the above link.

Android HorizontalScrollView snap

So I have a horizontalscrollview and I want to try add a snapping effect, that basically centers an element.
I have done it all in XML basically so far.
<HorizontalScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:scrollbars="none" >
And then I have a LinearLayout inside of it.
So how do I go about making the elements inside of the LinearLayout snap? Also, is there a way to make the layout start on the middle element? So when you see the scroller, you can scroll left or right from the start.
Would appreciate any help with this! Thanks guys!
Why don't you use viewpager (http://developer.android.com/reference/android/support/v4/view/ViewPager.html)?
but if you insist to use horizontal scroll view there are some tutorial out there you can follow like this
-http://www.dev-smart.com/archives/34
-http://blog.velir.com/index.php/2010/11/17/android-snapping-horizontal-scroll/
-http://androidprogrammingmadeeasy.blogspot.com/2011/08/creating-custom-horizontal-scroll-view.html

scrolling the background image in android java while adding a view to screen

I want to scroll the background in android. I have a scrollview which has many views. I need to implement a way wherein i need to scroll only the background while adding the views. I came across many forums but none of them are very clear. Please give an idea or references to implement it. To give more idea for what i am looking for is, Just consider a bike game wherein the background road image moves while riding the bike. I just need similar implementation while scrolling the screen.
Maybe you could do like this:
RelativeLayout as the parent
ScrollView with your image set as background
Then the other views, but outside of the ScrollView and inside of the RelativeLayout.
EDIT:
<RelativeLayout
android:id="#+id/relParent"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<OtherViews />
<ScrollView
android:id="#+id/scrlParent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/yourbackground">
</ScrollView>
</RelativeLayout>
I think that something like this might work. You see, the RelativeLayout is the parent. Then comes your other views, on the top of your ScrollView. Then, after your other views tag, comes the ScrollView, with only a background. I'm not sure if a background tag would work, so maybe you should remove the android:background="#drawable/yourbackground" and put an ImageView inside of the ScrollView.

Scrollbar does not scroll while using dynamically filled listview

I am not able to scroll in a scrollview which contains a listview and is filled dynamically as I get data from the webservice.
I am able to do scrolling in emulator through mouse wheel, but in avtual device I can not scroll the list.
The attributes of scrollview are
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginTop="10dp"
android:layout_weight="0.6"
android:fillViewport="true"
android:orientation="vertical"
android:padding="6.0dip"
android:scrollbarAlwaysDrawVerticalTrack="true"
android:scrollbarFadeDuration="5000"
android:scrollbarSize="20dp"
android:scrollbarStyle="insideOverlay"
android:scrollbars="vertical" >
<LinearLayout
android:id="#+id/linearLayout2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center_vertical"
android:orientation="vertical"
android:padding="2dp" >
<ListView
android:id="#+id/listbox_list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="599.84"
android:minHeight="250dp" >
</ListView>
</LinearLayout>
</ScrollView>
Please help me soon
by just looking at the layout_width and layout_height of your elements, it's clear that your scrollview will not scroll. unless you have a fixed height listview, never put a listview inside a scrollview (or in this case, a listview inside a layout that sits inside a scrollview).
I don't have any links to back this up right now, but it's not possible, and a well-known 'problem'. If you google a bit, or search here on SO, you'll find a number of topics covering this.
The problem arises in most cases when you have a scrolling view inside another scrolling view in the same direction. Consider the following example:
You have Two lists inside of a ScrollView.
Both lists are exactly one screen tall.
How do you scroll down to the second list?
When scrolling, how will your layout know if you are scrolling the list or the container?
This is basically the question that is the cause, and the only official solution is that it is as it should be, and there won't be a fix. Usually it is enough to have either a ListView or a ScrollView, but I have faced cases when you must have a listview in a scrollview (in my case a client wanted an iPhone-like datespinner in a scrolling page).
I solved it by using a FrameLayout, containing a custom ScrollView, and a ListView on top of that. Then in the code for the custom ScrollView, I added a line in the onScroll method that updated the top margin of the ListView, to psuh it upwards or downwards as the user scrolled. Surprisingly it worked.
NOTE: remember that:
The ListView handles its own scroll. If all you need is a scrolling
list, you do not need a ScrollView.
If you need a layout with a list and space for buttons or other
views, consider creating your layout so that the list only covers
enough space for you to fit your other views below/above without
scrolling.
Add following in your linear layout
android:scrollbars="vertical"
android:scrollbarAlwaysDrawVerticalTrack="true"

How to float/overlap a view in android?

I have many activities with a scrollview inside a tablelayout. However, it is necessary a small design change, so I have to put a black transparent view over the whole screen from the top to the bottom. Is it possible to do it in the tablelayout or the scrollview?
RelativeLayout allows for easy overlapping of views. You'll have to adjust the existing views in your app because it doesn't do anything automatically.
EDIT:
A quick way to do this would be to take your existing view (the ScrollView) that is already organized and put it in a top-level RelativeLayout. Then, all you have to do is add new view inside the RelativeLayout with the width and height both set to MATCH_PARENT. The result should be the black transparent view will be visible over the ScrollView.
I normally use FrameLayout to achieve any kind of 'layering' of views.
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
//your existing layout
<View
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#33000000" />
</FrameLayout>
As DeeV said, you can probably use RelativeLayout in a similar way, but you might have to set additional attributes on its children to achieve this.

Categories

Resources