I am planning to create a paginated scroll-to-bottom RecyclerView. But the onScrolled callback isn't being fired at all:
mBooksRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
#Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
Log.i("Dale", "scrolled");
}
});
mBooksRecyclerView.setNestedScrollingEnabled(false);
if (Utils.hasContent(books)) {
mBooksRecyclerView.setVisibility(View.VISIBLE);
BookCardViewAdapter adapter = new BookCardViewAdapter(this, books);
final GridLayoutManager gridLayoutManager = new GridLayoutManager(BooksActivity.this, 3);
mBooksRecyclerView.setLayoutManager(gridLayoutManager);
mBooksRecyclerView.setAdapter(adapter);
emptyView.setVisibility(View.GONE);
} else {
emptyView.setVisibility(View.VISIBLE);
mBooksRecyclerView.setVisibility(View.GONE);
}
I also tried removing the RecyclerView from a NestedScrollView and it still doesn't work.
Here is my XML files:
books_content.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/white"
android:orientation="vertical">
<RelativeLayout
android:id="#+id/header"
android:layout_width="match_parent"
android:layout_height="#dimen/books_category_height"
android:background="#color/gfs_blue">
<android.support.v7.widget.RecyclerView
android:id="#+id/categories_tab"
android:layout_width="match_parent"
android:layout_height="#dimen/books_category_height">
</android.support.v7.widget.RecyclerView>
</RelativeLayout>
<android.support.v7.widget.RecyclerView
android:id="#+id/sub_categories_tab"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/header"
android:layout_marginTop="20dp">
</android.support.v7.widget.RecyclerView>
<android.support.v7.widget.RecyclerView
android:id="#+id/books_recycler_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="#id/sub_categories_tab"
android:scrollbars="vertical" />
</RelativeLayout>
activity_books.gfs:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/white"
android:fitsSystemWindows="true"
tools:context=".activities.GFSBooksActivity">
<include
android:id="#+id/appbarlayout"
layout="#layout/appbarlayout"/>
<RelativeLayout
android:id="#+id/empty_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerInParent="true"
android:layout_below="#id/appbarlayout"
android:background="#color/white"
android:visibility="gone">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="No content found"
android:textColor="#color/gray"
android:textSize="20dp" />
</RelativeLayout>
<include
android:layout_width="match_parent"
android:layout_height="wrap_content"
layout="#layout/books_content"
android:layout_below="#+id/appbarlayout"/>
<!--<android.support.v4.widget.NestedScrollView-->
<!--android:layout_width="match_parent"-->
<!--android:layout_height="match_parent"-->
<!--app:layout_behavior="#string/appbar_scrolling_view_behavior">-->
<!--</android.support.v4.widget.NestedScrollView>-->
</RelativeLayout>
<android.support.design.widget.NavigationView
android:id="#+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="#layout/nav_header_main"
app:menu="#menu/activity_main_drawer" />
</android.support.v4.widget.DrawerLayout>
Initially, it was under a NestedScrollView but since it was mentioned that onScroll wouldn't be called if the RecyclerView is inside a NestedScrollView or a ScrollView, I removed the NestedScrollView.
I restarted my Android Studio and it is now working all along. But the fix probably was removing the RecyclerView inside the NestedScrollView.
You have disabled RecyclerView's scrolling. Hence, you will not receive any events of its scroll. You need to instead add the scroll event of parent of recyclerView which should be NestedScrollView not ScrollView.
Try this
int pastVisibleItem, visibleItemCount, totalItemCount, currentPage = 1, mPage = 1;
private boolean loading = true;
now use this method to implement pagination
mRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
#Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
super.onScrollStateChanged(recyclerView, newState);
}
#Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
//Log.e("checkkk", "cheeckk");
visibleItemCount = recyclerView.getChildCount();
totalItemCount = mLayoutManager.getItemCount();
pastVisibleItem = mLayoutManager.findFirstVisibleItemPosition();
if (loading) {
if ((visibleItemCount + pastVisibleItem) >= totalItemCount) {
loading = false;
currentPage++;
// do your stuff here
}
}
}
});
Related
I have an application that contains TabLayout with 5 tabs.
Now the need arose to click on an item in the RecycleView to open a new fragment within the Fragment that the user was already using, as if clicking on the item opened the subitems
My problem is that it uses ViewPager(Container)
In the parent Fragment I have the following code
#Override
public void onBindViewHolder(final RecyclerView.ViewHolder holder, final int position){
// MyListModel model = mList.get(holder.getAdapterPosition());
switch(holder.getItemViewType()){
case 1:{
MyViewHolder viewHolder = (MyViewHolder) holder;
viewHolder.Name.setTextColor(Color.parseColor("#245251")); //Todo Muda a cor da linha dos itens do RecycleView 08-08-2022
String nome = telemensagens.get(position).getName();
//String pasta = nome.substring(0,nome.lastIndexOf('-') );
String pasta = nome.lastIndexOf('_')>0 ? nome.substring(0,nome.lastIndexOf('_') ) : nome;
String index = nome.substring(nome.lastIndexOf('_') + 1).trim();
viewHolder.Name.setText(pasta);//telemensagens.get(position).getName());
viewHolder.Email.setText(telemensagens.get(position).getUrl());
final String music = telemensagens.get(position).getUrl();
viewHolder.Name.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Fragment myFragment;
/* Intent intent = new Intent(context, TelemensagensItensActivity.class);
intent.putExtra("PASTA", telemensagens.get(position).getName() );
context.startActivity(intent);*/
Bundle bundle = new Bundle();
String nome = telemensagens.get(position).getName();
if(MainActivity.nivelPasta==0)
MainActivity.nivelPastaFinal = nome.lastIndexOf('_')>0 ? Integer.parseInt(nome.substring(nome.lastIndexOf('_') + 1).trim()) : 1;
//MainActivity.nivelPastaFinal = Integer.parseInt(telemensagens.get(position).getName().substring(telemensagens.get(position).getName().length()-1,telemensagens.get(position).getName().length()));
MainActivity.nivelPasta++;
if(MainActivity.nivelPasta==MainActivity.nivelPastaFinal) {
myFragment = new AudiosItensActivity();
bundle.putString("PASTA",telemensagens.get(position).getName() );
MainActivity.audios.add(telemensagens.get(position).getName());
}
else {
myFragment = new AudiosActivity();
MainActivity.audios.add(telemensagens.get(position).getName());
bundle.putString("PASTA", MainActivity.nomePasta+ telemensagens.get(position).getName() );
MainActivity.nomeAudio += telemensagens.get(position).getName() + "/";
}
AppCompatActivity activity = (AppCompatActivity) context;
myFragment.setArguments(bundle);
activity.getSupportFragmentManager().beginTransaction().replace(R.id.container, myFragment,"Audio").
addToBackStack(null).commit();
}
});
break;
}
case 2:{
break;
}
}
}
In this specific piece of code is the click of the item in the recycleView, when clicking on it I can open a new child fragment, BUT it ends up killing my TabLayout, that is, the tabs stop working and I can no longer navigate in the other tabs
AppCompatActivity activity = (AppCompatActivity) context;
myFragment.setArguments(bundle);
activity.getSupportFragmentManager().beginTransaction().replace(R.id.container, myFragment,"Audio").addToBackStack(null).commit();
So my question is: How can I replace a single fragment and not my entire container with all fragments
Activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.drawerlayout.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:animateLayoutChanges="true"
android:fitsSystemWindows="true">
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res-auto"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="com.testapp.EventActivity">
<RelativeLayout
android:id="#+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="100dp">
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:id="#+id/coordinator"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#id/adViewMob"
android:layout_weight="1">
<com.google.android.material.appbar.AppBarLayout
android:id="#+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/AppTheme.AppBarOverlay">
<androidx.appcompat.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:layout_scrollFlags="scroll|enterAlways" />
<com.google.android.material.tabs.TabLayout
android:id="#+id/tab_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_scrollFlags="scroll|enterAlways"
app:tabTextAppearance="#style/MinhaCustomTabText" />
</com.google.android.material.appbar.AppBarLayout>
<LinearLayout
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/adViewMob"
android:layout_marginBottom="2dp"
android:animateLayoutChanges="true"
android:fitsSystemWindows="false"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
/>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
</RelativeLayout>
<com.google.android.gms.ads.AdView
android:id="#+id/adViewMob"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_gravity="bottom"
android:layout_marginTop="5dp"
ads:adSize="SMART_BANNER"
ads:adUnitId="#string/ad_unit_id" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
<com.google.android.material.navigation.NavigationView
android:id="#+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="#layout/nav_header_main">
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="170dp">
<com.dvinfosys.ui.NavigationListView
android:id="#+id/expandable_navigation"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="left"
android:divider="#null"
android:groupIndicator="#null"
android:scrollbars="vertical" />
</ScrollView>
</com.google.android.material.navigation.NavigationView>
</androidx.drawerlayout.widget.DrawerLayout>
fragment_container.xml
<FrameLayout
xmlns:ads="http://schemas.android.com/apk/res-auto"
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:layout_above="#id/adViewMob"
tools:context="com.mobileboss.bomdiatardenoite.ContainerFragment"
>
<androidx.viewpager.widget.ViewPager
android:id="#+id/viewPager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#id/adViewMob"
android:layout_marginBottom="0dp" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="?actionBarSize"
android:id="#+id/rltLayout"
xmlns:ads="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android">
</RelativeLayout>
</FrameLayout>
I have created this page indicator but i could not get it to a right position. I want it to be in the middle of the image or at the bottom of the image but it is at the very top near the back button and I tried but could not change its position.
Here is the image of the activity:
Here is the xml of the activity I am using. The Page indicator View as you see is under View Pager. Any type of help would be appreciated.
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:attrs="http://schemas.android.com/apk/res-auto"
android:background="#424242"
android:fitsSystemWindows="true">
<android.support.design.widget.AppBarLayout
android:id="#+id/appbar"
android:layout_width="match_parent"
android:layout_height="#dimen/appbar_header_height"
android:fitsSystemWindows="true"
android:theme="#style/Theme.AppCompat.Light.DarkActionBar">
<android.support.design.widget.CollapsingToolbarLayout
android:id="#+id/collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:expandedTitleMarginStart="#dimen/activity_margin_content"
app:layout_scrollFlags="scroll|exitUntilCollapsed|snap">
<android.support.v4.view.ViewPager
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/viewPager"
android:fitsSystemWindows="true"
android:scaleType="centerCrop"
app:layout_collapseMode="parallax"/>
<com.rd.PageIndicatorView
android:id="#+id/pageIndicatorView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="48dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
app:piv_animationType="worm"
app:piv_dynamicCount="true"
app:piv_interactiveAnimation="true"
app:piv_selectedColor="#color/gray_50"
app:piv_unselectedColor="#color/gray_300"
app:piv_viewPager="#id/viewPager"
attrs:piv_padding="12dp"
attrs:piv_radius="8dp" />
<View
android:layout_width="match_parent"
android:layout_height="160dp"
android:layout_gravity="bottom"
android:background="#drawable/scrim"/>
<android.support.v7.widget.Toolbar
android:id="#+id/anim_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light"/>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v7.widget.RecyclerView
android:id="#+id/rv"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
android:paddingBottom="#dimen/activity_margin_content"
android:paddingTop="#dimen/activity_margin_content"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:listItem="#layout/item_dessert"/>
viewPager = (ViewPager)findViewById(R.id.viewPager);
myCustomPagerAdapter = new MyCustomPagerAdapter(AnimateToolbar.this, images);
viewPager.setAdapter(myCustomPagerAdapter);
final PageIndicatorView pageIndicatorView = findViewById(R.id.pageIndicatorView);
viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
#Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {/*empty*/}
#Override
public void onPageSelected(int position) {
pageIndicatorView.setSelection(position);
}
#Override
public void onPageScrollStateChanged(int state) {/*empty*/}
});
the attrs are just the resources i have defined for how big the PageIndicatorView is it has nothing to do with its original positioning.
I'm working on creating a layout that works as follows:
Toolbar at the top
textView(a title) below top toolbar
RecyclerView
button
where the toolbar is in the main_activity
and the others are in an other xml file
And when I scroll, I want to hide the textView in between top toolbar and recyclerView.
why don't try the following, it might help
myRecyclerview.addOnScrollListener(new RecyclerView.OnScrollListener(){
#Override
public void onScrolled(RecyclerView rv, int dx, int dy) {
//boolean hasStarted = state == rv.SCROLL_STATE_DRAGGING; //Scrollbar is MOVING
//boolean hasEnded = state == rv.SCROLL_STATE_IDLE; //ScrollBar is NOT MOVING
//boolean isStopping = state == rv.SCROLL_STATE_SETTLING; //Scrollbar is STOPPING
if(dy > 0){
myTextview.setVisibility(View.VISIBLE);
}
}
});
and this is the main activity
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
>
<android.support.design.widget.AppBarLayout
android:id="#+id/appbar_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<FrameLayout
android:id="#+id/toolbar_container"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:layout_gravity="center"
app:titleMarginStart="10dp"
<com.miguelcatalan.materialsearchview.MaterialSearchView
android:id="#+id/search_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textAutoCorrect"
app:searchBackIcon="#drawable/ic_back_arrow"
app:searchVoiceIcon="#drawable/ic_voice_black"
/>
</FrameLayout>
</android.support.design.widget.AppBarLayout>
</android.support.design.widget.CoordinatorLayout>
I am using JakeWharton's ViewPagerIndicator on my landscape app but I think I am messing up with the layout. The ViewPagerIndicator does not show up. I just started learning Android Development so any help is appreciated!
My guess is that it has to do with my Linear Layout...should it be relative? Am I covering up the pager indicator? I know that if I move the indicator code above the view pager, I see the indicator but everything else is white. My fragment's layout is a relative layout with height and width matching the parent.
My app is an activity with fragments.
Edit: I set the indicator height to wrap content but now it floats on the top of the screen. How do I make it go down?
My_Activity.java
public class MyActivity extends FragmentActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_my);
ViewPager pager = (ViewPager) findViewById(R.id.viewPager);
MyPagerAdapter mAdapter = new MyPagerAdapter(getSupportFragmentManager());
pager.setAdapter(mAdapter);
CirclePageIndicator circleInd = (CirclePageIndicator) findViewById(R.id.circles);
circleInd.setViewPager(pager);
circleInd.setStrokeColor(0xAA000000);
//circleInd.setCurrentItem(mAdapter.getCount() - 1);
}
private class MyPagerAdapter extends FragmentPagerAdapter {
public MyPagerAdapter(FragmentManager fm) {
super(fm);
}
#Override
public Fragment getItem(int pos) {
switch (pos) {
case 0: return FirstFragment.newInstance("First");
case 1: return SecondFragment.newInstance("Second");
default: return FirstFragment.newInstance("First");
}
}
#Override
public int getCount() {
return 2;
}
}
}
and the XML
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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="com.example.frontrowqa.myfirstapplication.MyActivity">
<android.support.v4.view.ViewPager
android:id="#+id/viewPager"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</android.support.v4.view.ViewPager>
<com.viewpagerindicator.CirclePageIndicator
android:id="#+id/circles"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:padding="10dp"
android:layout_gravity="bottom" />
</LinearLayout>
And my fragment
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="20dp">
<EditText
android:id="#+id/PasscodeText"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:layout_width="fill_parent"
android:hint="Passcode"
android:backgroundTint="#android:color/black" />
<EditText
android:id="#+id/ipAddressText"
android:layout_below="#id/PasscodeText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="IP Address"
android:backgroundTint="#android:color/black" />
<EditText
android:id="#+id/intercomText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/ipAddressText"
android:hint="Intercom Event Number"
android:backgroundTint="#android:color/black"/>
<TextView
android:id="#+id/tvFragFirst"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:textSize="26dp"
android:text="TextView" />
</RelativeLayout>
Set your activity xml like this:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:orientation="vertical">
<android.support.v4.view.ViewPager
android:id="#+id/viewPager"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />
<com.viewpagerindicator.CirclePageIndicator
android:id="#+id/circles"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:padding="10dp" />
</LinearLayout>
I'm currently developing an application which have a ListView and a FAB. Now what i want to do is hide the FAB on the beginning and then show it after my ListView is scroll down. I have my content_main.xml where the ListView is coded, and activity_main.xml where my FAB is.
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".MainActivity">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="#style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<include layout="#layout/content_main" />
<android.support.design.widget.FloatingActionButton
android:id="#+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="#dimen/fab_margin"
android:src="#drawable/ic_up" />
</android.support.design.widget.CoordinatorLayout>
content_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context=".MainActivity"
tools:showIn="#layout/activity_main">
<ListView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/words_list_view"
android:divider="#00000000"
android:listSelector="#drawable/list_selector"
android:layout_weight="1" />
</RelativeLayout>
and in my Main_Activity.java i have onScrollListener where i'am stock, thinking that this is where i can handle the behavior of FAB.
listView.setOnScrollListener(new AbsListView.OnScrollListener() {
#Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
}
int preLast;
#Override
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
final int lastItem = firstVisibleItem + visibleItemCount;
if (lastItem > 20) {
if (preLast != lastItem) {
// SHow FAB Here
}
} else {
// Hide FAB Here
}
}
});
I hope you guys understand my problem. Thank You Very Much! Any Help Would Be Appreciated!