suramakr
Lurker
I need help with a Scroll issue that I am encountering in Android Tab Layout.
The issue is the tab fragments on pressing the scroll button keeps scrolling as though my tabviews have infinite size. I want it to stop once no more content is there. But not getting a hang of this.
**Picture to illustrate problem:**
[see this][1] and [see how the screen becomes white and keeps going on and on][2] There is an empty white canvas that keeps going on and on and keeps going. How do I stop this un-necessary scrolling?
My layout is like this
- Activity A (contains ListView using SimpleItemRecyclerViewAdapter)
- Onlick of list item, it creates another activity B for details of row
- Activity B creates a Fragment that uses SectionsPagerAdapter that extends FragmentPagerAdapter and this Fragment has a Tab Layout and shows 4 Tabs. Depending upon which Tab you select the SectionsPagerAdapter getItem(int pos) gets called and I return a new Instance (Fragment for that tab).
**Problem**: Now the problem is that the fragments all have a funny scroll behaviour, they don't clip when the layout content is no longer viewable.
When the tab fragment loads it shows all the listview items but it never stops once the last item content is rendered. Meaning, if I hit pagedown, or scroll down it keeps going in my emulator. Ideally I want it to stop once there are no more items / last element in the list view is shown or last button in my content view is rendered.
**Details of code**
I have a ListActivity.java that basically creates a fragment (that contains tablayout with 4 tabs). I use the RecyclerView that comes with the Android3.0 template.
In the same file, I listen to clicks on listview to create a detail view activity. That activity creates the needed fragments.
// when users click on a listitem I want to display tablayout with 4 tabs and also let it work with 2pane mode for tablets and phone. So I went with the android templete that basically uses Activity to render the fragment in one pane mode.
ListDetail activity then uses getSupportFragmentManager to manage the fragments in this activity and replace the container with the fragment.
I am now sharing the XML layout files I used for the above scenario.
I have used NestedScrollView since I needed scrolling and view full items. The activity that acts as a container for the tablayout fragment has this in the layout xml.
**activity_list_detail.xml**
Now the above activity uses a fragment that is basically a container for Toolbar + TabLayout + Tab Items.
**fragment_existing_listitem_detail**
Each of the tabs have their own fragment layout file like this
Each of the tabs are basically a separate fragment that get instatianted when the tabitem is clicked. I have a SectionsPagerAdapter that extends FragmentPagerAdapter for each tab item you click.
**What I have done so far to contain the problem:**
in my android.support.v4.view.ViewPager**
**app:layout_scrollFlags="scroll|enterAlways|snap"**
now it is possible I have overlooked something else. Please help.
The issue is the tab fragments on pressing the scroll button keeps scrolling as though my tabviews have infinite size. I want it to stop once no more content is there. But not getting a hang of this.
**Picture to illustrate problem:**
[see this][1] and [see how the screen becomes white and keeps going on and on][2] There is an empty white canvas that keeps going on and on and keeps going. How do I stop this un-necessary scrolling?
My layout is like this
- Activity A (contains ListView using SimpleItemRecyclerViewAdapter)
- Onlick of list item, it creates another activity B for details of row
- Activity B creates a Fragment that uses SectionsPagerAdapter that extends FragmentPagerAdapter and this Fragment has a Tab Layout and shows 4 Tabs. Depending upon which Tab you select the SectionsPagerAdapter getItem(int pos) gets called and I return a new Instance (Fragment for that tab).
**Problem**: Now the problem is that the fragments all have a funny scroll behaviour, they don't clip when the layout content is no longer viewable.
When the tab fragment loads it shows all the listview items but it never stops once the last item content is rendered. Meaning, if I hit pagedown, or scroll down it keeps going in my emulator. Ideally I want it to stop once there are no more items / last element in the list view is shown or last button in my content view is rendered.
**Details of code**
I have a ListActivity.java that basically creates a fragment (that contains tablayout with 4 tabs). I use the RecyclerView that comes with the Android3.0 template.
Code:
private void setupRecyclerView(@NonNull RecyclerView recyclerView) {
dbHandler = DBMS.getInstance(this); // singleton
dbHandler.getAllEntries(); //populate the listview
recyclerViewAdapter = new SimpleItemRecyclerViewAdapter(this, ListHelper.ITEMS, mTwoPane);
recyclerView.setAdapter(recyclerViewAdapter);
}
// when users click on a listitem I want to display tablayout with 4 tabs and also let it work with 2pane mode for tablets and phone. So I went with the android templete that basically uses Activity to render the fragment in one pane mode.
Code:
private final View.OnClickListener mOnClickListener = new View.OnClickListener() {
Intent intent = new Intent(context, ListDetailActivity.class);
context.startActivity(intent);
ListDetail activity then uses getSupportFragmentManager to manage the fragments in this activity and replace the container with the fragment.
I am now sharing the XML layout files I used for the above scenario.
I have used NestedScrollView since I needed scrolling and view full items. The activity that acts as a container for the tablayout fragment has this in the layout xml.
**activity_list_detail.xml**
Code:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
android:id="@+id/main_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
tools:context="ListDetailActivity">
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
android:layout_gravity="fill_vertical"
android:id="@+id/list_detail_container"
app:layout_behavior="[USER=696546]@String[/USER]/appbar_scrolling_view_behavior" />
</android.support.design.widget.CoordinatorLayout>
Now the above activity uses a fragment that is basically a container for Toolbar + TabLayout + Tab Items.
**fragment_existing_listitem_detail**
Code:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
android:id="@+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:backgroundTint="@color/primaryDarkColor"
android:fitsSystemWindows="true"
tools:context="ListDetail_Fragment">
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
androidaddingTop="@dimen/appbar_padding_top"
android:theme="[USER=19691]@Style[/USER]/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/fragment_toolbarID"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:layout_weight="1"
android:backgroundTint="@color/primaryColor"
app:layout_scrollFlags="scroll|enterAlways|snap"
apppopupTheme="[USER=19691]@Style[/USER]/AppTheme.PopupOverlay"
app:title="[USER=696546]@String[/USER]/app_name">
</android.support.v7.widget.Toolbar>
<android.support.design.widget.TabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.design.widget.TabItem
android:id="@+id/tabItem"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="[USER=696546]@String[/USER]/tab_text_1" />
<android.support.design.widget.TabItem
android:id="@+id/tabItem2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="[USER=696546]@String[/USER]/tab_text_2" />
<android.support.design.widget.TabItem
android:id="@+id/tabItem3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="[USER=696546]@String[/USER]/tab_text_3" />
<android.support.design.widget.TabItem
android:id="@+id/tabItem4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="[USER=696546]@String[/USER]/tab_text_4" />
</android.support.design.widget.TabLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="@+id/TabContainerID"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="[USER=696546]@String[/USER]/appbar_scrolling_view_behavior">
</android.support.v4.view.ViewPager>
</android.support.design.widget.CoordinatorLayout>
Each of the tabs have their own fragment layout file like this
Code:
<FrameLayout
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:context=Tab2_Fragment">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
androidrientation="vertical">
<!-- TODO: Update blank fragment layout -->
<Button
android:id="@+id/writeButtonID"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
androidOnClick="onClickWriteLog"
androidadding="@dimen/fab_margin"
android:gravity="center"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:layout_gravity="center_horizontal"
android:text="Write log"
android:textStyle="bold" />
<ListView
android:id="@+id/tab2_ListViewID"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
androidadding="@dimen/appbar_padding_top"
android:scrollbars="none"
android:visibility="visible" />
</LinearLayout>
</FrameLayout>
Each of the tabs are basically a separate fragment that get instatianted when the tabitem is clicked. I have a SectionsPagerAdapter that extends FragmentPagerAdapter for each tab item you click.
**What I have done so far to contain the problem:**
- On reading many of the responses, it seems there is something going on with my XML files. Trained eyes might locate it faster. I tried to execute my code with these changes, but the behaviour hasn't changed. Any help?
Code:
**app:layout_behavior="[USER=696546]@String[/USER]/appbar_scrolling_view_behavior"
in my android.support.v4.view.ViewPager**
- attention to
**app:layout_scrollFlags="scroll|enterAlways|snap"**
- attention to
- and finally use of right views
now it is possible I have overlooked something else. Please help.
Last edited:
