I am building a music player. I am working with bottomsheet. Its working fine and it has its peek height, But it covers the RecyclerView last item.
How can I set recyclerView above BottomSheet view.
Please help me.
Here is my MainActivity 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:id="#+id/tab_root"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/white">
<android.support.design.widget.AppBarLayout
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:background="#color/colorPrimary"
/>
<android.support.design.widget.TabLayout
android:id="#+id/tab_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/orange"
app:tabIndicatorColor="#color/colorAccent"
app:tabIndicatorHeight="3dp"
app:tabMode="fixed"
app:tabTextColor="#color/white" />
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="#+id/pager"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_behavior="#string/appbar_scrolling_view_behavior" />
<!-- View useed to load other fragments so that my Bottomsheet can be seen above other fragments -->
<FrameLayout
android:id="#+id/fragment_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
<!-- BottomSheet layout-->
<FrameLayout
android:id="#+id/framelayouts"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:elevation="8dp"
android:clickable="true"
app:layout_behavior="android.support.design.widget.BottomSheetBehavior">
<include layout="#layout/layout_player_bottomsheet" />
</FrameLayout>
</android.support.design.widget.CoordinatorLayout>
Please suggest what to do.
Add this two properties in your recyclerView.
android:clipToPadding="false"
android:paddingBottom="60dp"
Related
I made the Toolbar and TabLayout transparent. In TabLayout, I have two fragments with RecyclerView.
When I scroll, the contents of the recyclerView do not go under the tolbar. Please tell me how to fix.
I use the behaviour but it seems not working
app_bar_main.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".activity.MainActivity"
android:id="#+id/coordinator">
<android.support.v4.view.ViewPager
android:id="#+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="112dp"
android:background="#color/transparent" />
<android.support.design.widget.AppBarLayout
android:id="#+id/app_bar_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/transparent">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?android:attr/actionBarSize"
android:background="#color/transparent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView ..... />
<TextView ..... />
</LinearLayout>
</android.support.v7.widget.Toolbar>
<android.support.design.widget.TabLayout
android:id="#+id/tab_layout"
android:layout_height="?android:attr/actionBarSize"
android:layout_width="match_parent">
</android.support.design.widget.TabLayout>
</android.support.design.widget.AppBarLayout>
<android.support.design.widget.FloatingActionButton ..../>
</android.support.design.widget.CoordinatorLayout>
fragment.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"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context=".fragment.PoemFragment">
<android.support.v7.widget.RecyclerView
android:id="#+id/rvPoem"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="vertical"
android:clipToPadding="false"
android:paddingBottom="88dp"
app:layout_behavior="#string/appbar_scrolling_view_behavior" />
</RelativeLayout>
You should use this behavior in root of that view that want to place below of AppBarLayout, not in child of views (Fragments)
just add this behavior to ViewPager
just change :
<android.support.v4.view.ViewPager
android:id="#+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="112dp"
android:background="#color/transparent" />
to :
<android.support.v4.view.ViewPager
android:id="#+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="112dp"
android:background="#color/transparent"
app:layout_behavior="#string/appbar_scrolling_view_behavior" />
I am searching for a way to make my recycleView elastic at the top when pulled. Let me show you a image of what i want:
https://raw.githubusercontent.com/baoyongzhang/android-PullRefreshLayout/master/demo.gif
So you can see from that gif, that when the user pulls down on the very top of the list it kind of has an elastic bounce affect. How do i achieve that ? i want this affect so my swipeRefreshLayout doesn't get triggered so easily just by reaching the top. i want them to actually PULL to refresh not just reach the top. my appbar layout looks like this right now:
<?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"
android:id="#+id/main_content"
android:layout_width="match_parent"
android:fitsSystemWindows="false"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:id="#+id/id_appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#android:color/white">
<android.support.design.widget.CollapsingToolbarLayout
android:id="#+id/collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:contentScrim="#color/white"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
app:titleEnabled="false">
<com.mobile..UI.customViews.CategoryBanner
android:id="#+id/shortcutbanner"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_collapseMode="parallax" />
<include layout="#layout/toolbar" />
</android.support.design.widget.CollapsingToolbarLayout>
<android.support.design.widget.TabLayout
android:id="#+id/tabLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabGravity="fill"
app:tabMode="fixed"
android:elevation="6dp"
app:tabSelectedTextColor="#android:color/darker_gray"
app:tabTextColor="#color/black" />
</android.support.design.widget.AppBarLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="fill_vertical"
android:orientation="vertical">
<com.mobile.UI.customViews.HomePageViewPager
android:id="#+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="fill_vertical"
/>
</LinearLayout>
</FrameLayout>
</android.support.design.widget.CoordinatorLayout>
and inside of a tab i have the following recyclerView:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v4.widget.SwipeRefreshLayout
android:id="#+id/swipefeedRefreshLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.mobile.UI.customViews.VelocityControlRecyclerView
android:id="#+id/recyclerView"
android:layout_marginTop="0dp"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</android.support.v4.widget.SwipeRefreshLayout>
</LinearLayout>
in my activity i tried calling this but it does not work:
mRecyclerView.setOverScrollMode(View.OVER_SCROLL_ALWAYS);
I have some problem with coordinator layout. I have activity toolbar inside appBarLayout with parent CoordinatorLayout (I want to make toolbar hideable) and fragment with tablayout inside appBarLayout and viewPager. Here is activity's 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"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/gradient"
android:fitsSystemWindows="true">
<android.support.design.widget.AppBarLayout
android:id="#+id/toolbar_container"
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:layout_scrollFlags="scroll|enterAlways|snap"
app:popupTheme="#style/AppTheme.PopupOverlay"/>
</android.support.design.widget.AppBarLayout>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/content"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</android.support.design.widget.CoordinatorLayout>
And it's fragment's 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"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/gradient"
android:fitsSystemWindows="true">
<android.support.design.widget.AppBarLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/toolbar_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/AppTheme.AppBarOverlay">
<android.support.design.widget.TabLayout
android:id="#+id/tabs"
style="#style/MyCustomTabLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabGravity="fill"/>
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="#+id/viewPager"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior"/>
</android.support.design.widget.CoordinatorLayout>
For now, I have this situation where the toolbar is somewhere.
If I change coordinator layout inside activity to linear layout I get toolbar visible, but as you can imagine with no hiding option.
Actually, I have play with coordinator layout a lot:hiding and showing toolbar in a few cases such parallax and others - https://github.com/Iamtodor/toolbars, so you can be sure, I have a little understand how it works :)
Also, I had wantch this sources:
- https://github.com/codepath/android_guides/wiki/Handling-Scrolls-with-CoordinatorLayout
- https://github.com/codepath/android_guides/wiki/Using-the-App-ToolBar#using-toolbar-as-actionbar
- https://github.com/chrisbanes/cheesesquare
But there is all examples when tablayout exists inside same appbarlayout with toolbar.
How can I fix it?
Here is what worked for me:
Fragment XML:
<android.support.design.widget.AppBarLayout
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/app_bar_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:elevation="0dp">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_scrollFlags="scroll|enterAlways|snap" >
<include layout="#layout/include_time_line"
android:layout_height="wrap_content"
android:layout_width="match_parent" />
</android.support.v7.widget.Toolbar>
<android.support.design.widget.TabLayout
style="#style/TabLayout"
android:id="#+id/tabLayout"
android:layout_width="match_parent"
android:layout_height="54dp"
android:layout_gravity="bottom"
android:background="#color/egg"
android:elevation="0dp"
app:tabGravity="fill"
app:tabMode="scrollable"
app:tabIndicatorColor="#fcd131"
app:tabPadding="0dp"
app:tabIndicatorHeight="4dp"/>
</android.support.design.widget.AppBarLayout>
<com.woot.woot.productbrowse.ui.ConfigurablePagingViewPager
android:id="#+id/viewPager"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
/>
<FrameLayout
android:id="#+id/selectByWeightKeyboard"
android:layout_width="match_parent"
android:layout_height="#dimen/weight_keyboard_container_height"
android:background="#color/keyboard"
android:clipToPadding="false"
android:elevation="16dp"
android:clickable="true"
app:layout_behavior="android.support.design.widget.BottomSheetBehavior">
<include layout="#layout/add_product_by_weight_keyboard" />
</FrameLayout>
Activity XML:
<FrameLayout
android:id="#+id/contentFrame"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<FrameLayout
android:id="#+id/layout_done_button"
android:visibility="gone"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:elevation="8dp"
tools:visibility="visible"
android:background="#color/ice">
<Button
android:id="#+id/button_done"
style="?android:attr/borderlessButtonStyle"
android:layout_width="match_parent"
android:layout_height="#dimen/button_height"
android:layout_marginRight="#dimen/button_done_horizontal_margin"
android:layout_marginLeft="#dimen/button_done_horizontal_margin"
android:layout_marginTop="#dimen/activity_horizontal_margin"
android:layout_marginBottom="#dimen/activity_horizontal_margin"
android:background="#drawable/rounded_green_button"
android:text="#string/done"
android:textSize="#dimen/button_text_size"
android:textAllCaps="true"
android:textColor="#color/egg" />
</FrameLayout>
<android.support.design.widget.NavigationView
android:id="#+id/navigation"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:contentDescription="#string/drawer_content_description"
app:menu="#menu/menu_navigation_product_browse" />
Actually i am trying to build a listView/recyclerView . On scrolling of list the actionbar get hide where action bar is toolbar but the some part of listview is hiding behind the tab. Here i have used AppBarLayout and toolbar having app:layout_scrollFlags="scroll|enterAlways" and in my recylerview have app:layout_behavior="#string/appbar_scrolling_view_behavior" behaviour. I can use linear Layout but problem is for sliding of toolbar the AppBarLayout must be the child of CoordinatorLayout.
My activity having 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"
tools:context="ameyo.genie.activity.HomeActivity">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="50dp">
<android.support.v4.view.ViewPager
android:id="#+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</FrameLayout>
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
android:background="?attr/colorPrimary"
android:minHeight="?attr/actionBarSize"
app:popupTheme="#style/Theme.AppCompat.Light.DarkActionBar"
app:theme="#style/Toolbar">
<android.support.v7.widget.Toolbar
android:id="#+id/action_bars"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_scrollFlags="scroll|enterAlways"
/>
<ameyo.genie.SlidingTabLayout
android:id="#+id/sliding_tabs"
android:layout_width="match_parent"
android:layout_height="48dp"
android:background="#color/colorPrimary"
/>
</android.support.design.widget.AppBarLayout>
<android.support.design.widget.FloatingActionButton
android:id="#+id/home_fab_dial"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:clickable="true"
android:src="#drawable/ic_dialpad_white"
app:layout_anchor="#id/pager"
app:layout_anchorGravity="bottom|center" />
</android.support.design.widget.CoordinatorLayout>
and my fragment having
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
android:id="#+id/main_content"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/white">
<android.support.v7.widget.RecyclerView
android:id="#+id/recentcall_recyclerview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
/>
</android.support.design.widget.CoordinatorLayout>
Am I doing something wrong in making the toolbar to slide on sliding the listview or there is another way of doing this without using any third library.
try this:
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
android:background="?attr/colorPrimary"
android:minHeight="?attr/actionBarSize"
app:popupTheme="#style/Theme.AppCompat.Light.DarkActionBar"
app:theme="#style/Toolbar">
<android.support.v7.widget.Toolbar
android:id="#+id/action_bars"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_scrollFlags="scroll|enterAlways"
/>
<ameyo.genie.SlidingTabLayout
android:id="#+id/sliding_tabs"
android:layout_width="match_parent"
android:layout_height="48dp"
android:background="#color/colorPrimary"
/>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="50dp">
<android.support.v4.view.ViewPager
android:id="#+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</FrameLayout>
</android.support.design.widget.AppBarLayout>
When you put your component, order them by the position, every component will be over the precedent, if there's no space !
Thanks to Daniel Nugent that I forgot to write android:layout_below="#+id/sliding_tabs" inside viewpager and also remove framelayout and height must be wrapcontent now my final code is this which is working
<?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"
tools:context="ameyo.genie.activity.HomeActivity">
<android.support.design.widget.AppBarLayout
android:id="#+id/appBarLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:elevation="6dp">
<android.support.v7.widget.Toolbar
android:id="#+id/action_bars"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:background="?attr/colorPrimary"
android:minHeight="?attr/actionBarSize"
app:popupTheme="#style/Theme.AppCompat.Light.DarkActionBar"
app:theme="#style/Toolbar"
app:elevation="0dp"
app:layout_scrollFlags="scroll|enterAlways"
/>
<ameyo.genie.SlidingTabLayout
android:id="#+id/sliding_tabs"
android:layout_below="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="48dp"
android:background="?attr/colorPrimary"
app:elevation="0dp"
android:minHeight="?attr/actionBarSize"
/>
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="#+id/pager"
android:layout_below="#+id/sliding_tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
/>
<android.support.design.widget.FloatingActionButton
android:id="#+id/home_fab_dial"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:clickable="true"
android:src="#drawable/ic_dialpad_white"
app:layout_anchor="#id/pager"
app:layout_anchorGravity="bottom|center" />
</android.support.design.widget.CoordinatorLayout>
I am using the design support library to build a material viewpager. The code for the xml file is as follows:
<?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"
android:id="#+id/coordinatorLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:id="#+id/appBarLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.v7.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"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light" />
<android.support.design.widget.TabLayout
android:id="#+id/tabLayout"
style="#style/TabLayoutStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="#+id/viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior" />
</android.support.design.widget.CoordinatorLayout>
One of the fragments on the viewpager has a recycler view inside a relative layout. The code is:
<?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"
android:id="#+id/layout"
android:layout_width="match_parent"
android:padding="2.5dip"
android:layout_height="match_parent"
android:orientation="vertical">
<ProgressBar
android:id="#+id/progressBar"
style="?android:attr/progressBarStyleLarge"
android:layout_width="50dip"
android:layout_height="50dip"
android:layout_centerInParent="true"
android:layout_margin="20dip"
android:indeterminate="false" />
<android.support.v7.widget.RecyclerView
android:id="#+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="none"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
android:visibility="gone" />
</RelativeLayout>
The result i want is when the recyclerview scrolls, the toolbar should scroll away from view leaving the tablayout only, but what i have is on scroll, the tablayout scrolls out of view leaving the toolbar.
How can i achieve this?