Android Scrollview infinite scrolling - android

I have a problem with Android's ScrollView. I am facing infinite vertical scrolling. Even though I've run out of elements, I can keep scrolling through white space. I want the ScrollView to scroll down to the end of relative Layout. If you have any solution for this it would be much appreciated.
Thanks in advance
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/scroll1"
>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:id="#+id/info"
android:background="#color/main_backgroundColor" >
<LinearLayout
android:id="#+id/Line"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
</LinearLayout>
<com.etsy.android.grid.StaggeredGridView
android:id="#+id/mainGridview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:numColumns="2"
android:scrollbars="none"
android:stretchMode="columnWidth"
android:layout_below="#+id/Line"
android:verticalSpacing="1dp" />
<WebView
android:id="#+id/WebView_home"
android:layout_width="0dp"
android:layout_height="0dp"
android:visibility="invisible" />
</RelativeLayout>
</ScrollView>

Ofcourse I don't know the structure of your project but why you don't use ListView with CWAC MergeAdapter? It can help you with infinite scroll.
Here is a link: https://github.com/commonsguy/cwac-merge

Related

ScrollView not displaying all Contents in Homefragment

I am trying to disable scrollview and show up all contents in homepage, However till no luck scroll doesn't show up all the contents.I already tried all questions regarding this but still no luck. I would appreciate if anyone could help me.Thank You :)
Here is fragment_home.xml..
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"
android:background="#color/bg">
<ProgressBar
android:id="#+id/progressBar"
style="#style/Widget.AppCompat.ProgressBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:visibility="gone" />
<ScrollView
android:id="#+id/scrollView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<FrameLayout
android:id="#+id/ContainerSlider"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<android.support.v7.widget.RecyclerView
android:id="#+id/rv_latest"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp" />
<android.support.v7.widget.RecyclerView
android:id="#+id/rv_featured"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp" />
</LinearLayout>
</ScrollView>
</RelativeLayout>
Did you try adding to scrollview
android:fillportView="true"
You also dont need two recyclerview.. Do one with multiple view types.
With that said you also dont need that scrollview. You only need one recyclerview with multiple viewtypes.
Your layout can be handled well by using EPOXY, a library from airbnb.
Will make your life a lot easier.
https://github.com/airbnb/epoxy
Have you tried using NestedScrollView instead?
The LinearLayout should also have a height of match_parent instead of wrap_content.
Also you should only use weight for views that are children of a LinearLayout so you can remove that for the NestedScrollView.
<NestedScrollView
android:id="#+id/scrollView"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

I can't set Horitonzal scrollbar in gridview in android

this is my code ,
i want visiable horitonzal scrollbar in gridview , so i tried to fix it , my gridview have 1row and 3 Columns , icant use vertical scroll because content page have scroll
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_below="#+id/linearLayout2"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="false"
android:id="#+id/linearLayout3"
android:background="#android:drawable/dialog_holo_light_frame">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="طرح های پیشنهادی"
android:id="#+id/textView3"
android:paddingRight="10dp"
android:paddingTop="5dp"
android:layout_gravity="right"
android:textColor="#cc0066"
android:textStyle="bold" />
<GridView
android:id="#+id/gridview1"
android:layout_width="match_parent"
android:layout_height="80dp"
android:columnWidth="90dp"
android:gravity="center"
android:horizontalSpacing="10dp"
android:verticalSpacing="5dp"
android:numColumns="auto_fit"
android:scrollbars="horizontal" />
</LinearLayout>
</HorizontalScrollView>
you can either enable nestedscrolling in xml or you can enclose your gridview inside a nestedScrollView . Try that , if that's not working let me know.
Did you try to add ScrollView?
HERE is that people already talked about that. If i didn't understand you wrong.
I adding example codes for vertical and horizontal.
How to scroll gridview to position?
How can I add a vertical scrollbar to a gridview?
Firstly, end of the LinearLayout, get rid of the slash: /> to >
Here is direct answer for your question:
Put into ScrollView:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true"
android:scrollbars="vertical">
<!-- your codes here -->
</ScrollView>
For horizontal:
<HorizontalScrollView>
<ScrollView>
<!-- your codes here -->
</ScrollView>
</HorizontalScrollView>

Android Layout XML: Divider below Listview

Because of the design of the app, I need to do the following:
(I reduced the problem as much as possible - and searched in other answers, but havent found my problem exactly)
As you can see in the picture, I have following components:
Listview
GreenDivider with a fixed size of 1dp
Button-Area
The Listview is on top, the button-area in the bottom and the divider between them. The Listview is variable in its size.
Following is the difficult part:
The divider has always be visible.
The divider has always to be above the button-area. If the listview does not use the entire available space, the divider has to be exactly below the listview. If the Listview uses more space than available, the divider has to be exactly above the button-area. And of course, the listview should be scrollable.
I tried a long time with relative layout and also with weight in linearlayout. If you got a solution, please share your idea with me.
The following is the part of the layout, but it actually does not work as expected:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ListView
android:id="#+id/notification_action_listview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#drawable/navigation_item_background_selector"
android:divider="#null"
android:dividerHeight="0dp"
android:orientation="vertical" />
</LinearLayout>
<LinearLayout
android:id="#+id/divider_layout"
android:layout_width="fill_parent"
android:layout_height="1dp" >
<include
android:id="#+id/divider"
android:layout_width="fill_parent"
android:layout_height="1dp"
layout="#layout/divider_horizontal_green" />
</LinearLayout>
<LinearLayout
android:id="#+id/footer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center|bottom"
android:orientation="vertical" >
<Button
android:id="#+id/notification_action_remove_button"
style="#style/flat_button_red_rounded"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="#dimen/margin_big"
android:paddingLeft="#dimen/margin_big"
android:paddingRight="#dimen/margin_big"
android:text="#string/delete_account" />
</LinearLayout>
</LinearLayout>
Use a relative layout as your top level. set the footer to alignBottom, and the LinearLayout that contains the Listview and the separator to layout_above="#id/footer". I have edited your xml to solve your problem (I think its properly formed but SO isn't the best editor).
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:alignParentTop="true"
android:layout_above="#id/footer">
<ListView
android:id="#+id/notification_action_listview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#drawable/navigation_item_background_selector"
android:divider="#null"
android:dividerHeight="0dp"
android:orientation="vertical" />
<include
android:id="#+id/divider"
android:layout_width="fill_parent"
android:layout_height="1dp"
layout="#layout/divider_horizontal_green" />
</LinearLayout>
<LinearLayout
android:id="#+id/footer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignBottom="true"
android:orientation="vertical" >
<Button
android:id="#+id/notification_action_remove_button"
style="#style/flat_button_red_rounded"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="#dimen/margin_big"
android:paddingLeft="#dimen/margin_big"
android:paddingRight="#dimen/margin_big"
android:text="#string/delete_account" />
</LinearLayout>
</RelativeLayout>
I would declare two dividers and give them each an id.
Then, programatically, I would check the size of the list view against the size of its container.
If the listview is bigger than the container I would make the divider parked above the buttons "visible" and the one below the listview "gone"
etc...
Truthfully, I'd probably just align it above the buttons and call it a day.

How to set listviews in horizontalScrollView to fill up the screen?

I have three listviews in horizontalScrollView. I want to make each of them to occupy the full screen, by including them into a linearlayout which is set to (layout_width: match_parent, layout_height: match_parent). However, it doesn't work. As you see from the screenshot, the three listviews just tightly linked with one another.
Any suggestions so that the three listviews each occupies the full screen? THx a lot.
<HorizontalScrollView
android:id="#+id/horizontalScrollView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#color/page_bg_color">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ListView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/tab_login_myFriends_requestList"
android:background="#ffffffff" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ListView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/tab_login_myFriends_pendingList"
android:background="#ffffffff" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ListView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/tab_login_myFriends_confirmedList"
android:background="#ffffffff" />
</LinearLayout>
</LinearLayout>
</HorizontalScrollView>
Use this,
http://developer.android.com/reference/android/widget/ScrollView.html#attr_android:fillViewport
Set that to true. Also your listviews should probably have a weight attribute associated with them.
But I can't really figure out what you're trying to do. Maybe provide the xml and I'll guide you further.
I think what you're looking for is this,
http://developer.android.com/training/animation/screen-slide.html

Why position allways scroll to gridview's position inside my ScrollView?

I use a vertical ScrollView to carry ViewPager and Gridview. ViewPager's position is above the Gridview,and Gridview is use "expand all" to keep it behaviors well inside scrollview.
But. After I use adapter to fill content to these two view. The position is always scroll to Gridview's position at first.User need to scroll it up to see Viewpager themself.
I want its position can at the first viewpager, not the gridview.
Could you give me some suggestions.
Thanks.
The following is my layout file.
<ScrollView
android:id="#+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
android:scrollbarAlwaysDrawVerticalTrack="true" >
<LinearLayout
android:id="#+id/linearlayout_dynamicRoot"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<FrameLayout
android:id="#+id/viewpager_fl"
android:layout_width="fill_parent"
android:layout_height="160dp" >
<myViewPager
android:id="#+id/vp"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</FrameLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="40dp"
android:background="#B0000000"
android:gravity="center"
android:orientation="horizontal" >
<LinearLayout
android:id="#+id/ll_dot_dynamic"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:gravity="center"
android:orientation="horizontal" >
<TextView
android:layout_width="0dp"
android:layout_height="0dp" />
</LinearLayout>
<TextView
android:id="#+id/tv_title"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:ellipsize="end"
android:gravity="center_vertical|center_horizontal"
android:maxLines="1"
android:textColor="#FF7700"
android:textSize="20dp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="#+id/tv1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="GridView_Header1"
android:textColor="#ff7700"
android:textSize="20dp"
android:visibility="gone" />
<GridView
android:id="#+id/gv1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
</GridView>
</LinearLayout>
</LinearLayout>
</ScrollView>
Further reading has revealed that there are issues with scrolling components inside scrolling components.
One solution is to 'disable' the vertical scrolling of the ScrollView on the area of the contained scrollable component, in my case a ViewPager.
The code for this solution is detailed here(HorizontalScrollView within ScrollView Touch Handling) (and its simply brilliant!)

Categories

Resources