I am using ViewPager and RecyclerView in a FrameLayout.
<FrameLayout 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=".HomeActivity">
<android.support.v4.view.ViewPager
android:id="#+id/top_container"
android:layout_width="match_parent"
android:layout_height="300dp"
/>
<android.support.v7.widget.RecyclerView
android:id="#+id/regular_view"
android:clipToPadding="false"
android:paddingTop="300dp"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
I want to hide the ViewPager on Scroll of RecyclerView vertically. It is working.
However the scroll of ViewPager is not working. Why it is happening ?
here is an example for drawer layout used to implement left navigation Drawer
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/drawer_layout"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:fitsSystemWindows="true">
<include
android:id="#+id/app_bar_main_activity"
android:layout_width="fill_parent"
android:layout_height="#dimen/app_bar_height"
layout="#layout/app_bar" />
<FrameLayout
android:id="#+id/frame_container"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
</FrameLayout>
</LinearLayout>
<fragment
android:id="#+id/navigation_drawer"
android:layout_width="280dp"
android:layout_height="fill_parent"
android:layout_gravity="start"
android:name="sub.fragments.NavigationDrawer"
tools:layout="#layout/fragment_navigation_drawer"
app:layout="#layout/fragment_navigation_drawer">
</fragment>
in this Linear layout acts as host for different layout for separate Fragments which can be replaced with framlayout
and next Fragment can be anything you want, here's a fragment you can have RecyclerView
Related
I have 3 fragments and im trying to use the slidinguppanel from this library https://github.com/umano/AndroidSlidingUpPanel.
But how can i use the same slidinguppanel across all fragments, so the content stays the same and i don't have to make another sliding up panel in the other layout?
This is my xml for fragment 1
<com.sothree.slidinguppanel.SlidingUpPanelLayout
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/mSlideUpPanel"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="bottom"
tools:context=".fragments.Tab1"
app:umanoPanelHeight="70dp"
app:umanoShadowHeight="5dp">
<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"
tools:context=".fragments.Tab1">
<android.support.v7.widget.RecyclerView
android:id="#+id/recyclerViewSongs"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentStart="true">
</android.support.v7.widget.RecyclerView>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<include layout="#layout/activity_song" />
</RelativeLayout>
Having an issue with a map fragment on my one activity, basically i have created a bottom navigation view and my map fragment is going behind my bottom navigation view no matter what i do. I'm not sure how to get it to respect my layout and sit above my bottom navigation view.
I have a scrollview with all my content inside it, including the map fragment and then a bottom navigation view outside of my scroll view so that it remains fixed to the bottom of the layout.
<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:orientation="vertical"
android:fitsSystemWindows="true">
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/scrollview"
android:orientation="vertical">
<RelativeLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<!-- My content -->
<fragment
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:map="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/map"
android:layout_below="#+id/details"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="300dp"
map:cameraZoom = "15"
map:uiZoomControls = "true" />
</RelativeLayout>
</ScrollView>
<LinearLayout
android:id="#+id/toolbar_footer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#android:color/white"
android:layout_alignParentBottom="true"
android:orientation="vertical"
xmlns:app="http://schemas.android.com/apk/res-auto">
<android.support.design.widget.BottomNavigationView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/bottom_toolbar"
android:background="#drawable/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="start"
app:menu="#menu/toolbar_item" />
</LinearLayout>
</RelativeLayout>
update code
android:layout_above="#+id/toolbar_footer"
...
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/scrollview"
android:orientation="vertical"
android:layout_above="#+id/toolbar_footer"
android:fillViewport="true">
...
I can't seem to get rid of this grey bar because of my margin in the below XML that is set to the ActionBar height. Eventually an actionbar appears but transparent but how do I get rid of this grey background from the start? If I use paddingTop then my actionbar is not clickable.
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/transparent"
android:orientation="vertical">
<include
android:id="#+id/action_bar"
layout="#layout/action_bar" />
</RelativeLayout>
<FrameLayout
android:layout_marginTop="?attr/actionBarSize"
android:id="#+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<ListView android:id="#+id/left_drawer"
android:background="#FFFFFF"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="left|start"
android:choiceMode="singleChoice"/>
</android.support.v4.widget.DrawerLayout>
Use a RelativeLayout parent for all other layouts inside your Drawer.
And set the FrameLayout to stay below the appBar, like that:
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:id="#+id/action_bar_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/transparent"
android:orientation="vertical">
<include
android:id="#+id/action_bar"
layout="#layout/action_bar" />
</RelativeLayout>
<FrameLayout
android:id="#+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#id/action_bar_container" />
<ListView android:id="#+id/left_drawer"
android:background="#FFFFFF"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="left|start"
android:choiceMode="singleChoice"/>
</RelativeLayout>
</android.support.v4.widget.DrawerLayout>
This should work, it should move the frame layout below the action bar only if it's visible!
This can help you...
or try to add custom toolbar... make a separate layout file with the content like below`
<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/gradient"
app:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light" />
</android.support.design.widget.AppBarLayout>
`
and include it with include tag in your drawer layout... Get the toolbar by findViewById(...) and set it using setSupportActionBar(Toolbar toolbar) method.
I have a relative layout in which i have two child .one is drawer layout and the other is a frame layout in which i have used a fragment .The problem is when i keep drawer layout in the top and the frame layout in the bottom,drawer layout doesn't work and if do the opposite,frame layout doesn't
this is my relative layout
<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">
<include
android:id="#+id/toolbar_actionbar"
layout="#layout/mtoolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/toolbar_actionbar">
<fragment
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:name="com.example.rohit.newmastervocab.FloatingFragment"
android:id="#+id/fragment2"
android:layout_alignParentStart="true"
tools:layout="#layout/fragmentfloating"
android:layout_alignTop="#+id/drawer"
android:layout_gravity="center_horizontal|bottom" />
</FrameLayout>
<android.support.v4.widget.DrawerLayout android:id="#+id/drawer1"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent"
android:layout_below="#+id/toolbar_actionbar"
android:layout_alignParentBottom="true">
<ListView
android:id="#+id/drawerlist1"
android:layout_width="240dp"
android:layout_height="match_parent"
android:entries="#array/navigation_items"
android:background="#F3F6C8"
android:layout_gravity="start">
</ListView>
</android.support.v4.widget.DrawerLayout>
</RelativeLayout>
Mike M. is absolutely right: you need to keep FrameLayout as one of the Children of DrawerLayout.
I've updated your XML a bit, take a look:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
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
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar_actionbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="#style/AppTheme.PopupOverlay" />
<FrameLayout
android:layout_below="#+id/toolbar_actionbar"
android:layout_width="match_parent"
android:layout_height="match_parent">
<fragment
android:layout_gravity="center_horizontal|bottom"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:name="com.example.rohit.newmastervocab.FloatingFragment"
android:id="#+id/fragment2"/>
</FrameLayout>
</RelativeLayout>
<ListView
android:id="#+id/drawerlist1"
android:layout_width="240dp"
android:layout_height="match_parent"
android:entries="#array/navigation_items"
android:background="#F3F6C8"
android:fitsSystemWindows="true"
android:layout_gravity="start"/>
</android.support.v4.widget.DrawerLayout>
Now drawer works just as expected and Fragment is stick to the bottom|center of the screen.
I have the following Layout and I want to hide the LinearLayout "cv" and its included child behind the toolbar.
I searched for it and found a lot of Examples to hide the toolbar, but none of them showed me to hide any other View than the toolbar (example). Is there a possibility to do it with a CoordinatorLayout?
<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"
tools:context="de.app.activities.AccountDetail">
<include
android:id="#+id/app_bar"
layout="#layout/app_bar" />
<LinearLayout
android:id="#+id/cv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/app_bar">
<include layout="#layout/single_account" />
</LinearLayout>
<android.support.v4.widget.SwipeRefreshLayout
android:id="#+id/swipeRefreshLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/cv">
<android.support.v7.widget.RecyclerView
android:id="#+id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</android.support.v4.widget.SwipeRefreshLayout>
</RelativeLayout>