Display LinearLayout below RecyclerView - android

I'm using a RecyclerView to display a list of items, and I would like to show below the list a box with some details but I don't how to do it, I have tried a lot of things but I cant display the box I want.
My idea is implement something like in the image below:
Below is my code:
<?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:background="#color/backgroundColor">
<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>
<android.support.v7.widget.RecyclerView
android:id="#+id/user_subscriptions"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="12dp"
android:paddingBottom="10dp"
app:layout_behavior="#string/appbar_scrolling_view_behavior"/>
// HERE I'M TRYING TO ADD THE BOX.
<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_add" />
</android.support.design.widget.CoordinatorLayout>
Any idea how can I do it? Thanks!

try this one hope this will help you.
<?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.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
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:layout_above="#+id/bottomBox"
android:fitsSystemWindows="true">
<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="?attr/colorPrimary" />
</android.support.design.widget.AppBarLayout>
<android.support.v7.widget.RecyclerView
android:id="#+id/user_subscriptions"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="10dp"
android:paddingTop="12dp"
app:layout_behavior="#string/appbar_scrolling_view_behavior" />
<android.support.design.widget.FloatingActionButton
android:id="#+id/fab"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="15dp"
android:background="#color/colorPrimary" />
</android.support.design.widget.CoordinatorLayout>
<LinearLayout
android:id="#+id/bottomBox"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_alignParentBottom="true"
android:background="#android:color/white"
android:orientation="vertical" />
</RelativeLayout>

You can do it like this
<?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:background="#color/backgroundColor">
<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>
// HERE I'M TRYING TO ADD THE BOX.
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<View
android:id="#+id/box"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_alignParentBottom="true"
/>
<android.support.v7.widget.RecyclerView
android:id="#+id/user_subscriptions"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="12dp"
android:paddingBottom="10dp"
android:layout_above="#id/box"
app:layout_behavior="#string/appbar_scrolling_view_behavior"/>
</RelativeLayout>
<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_add" />
</android.support.design.widget.CoordinatorLayout>

Use app:layout_behavior="#string/appbar_scrolling_view_behavior like this:-
<?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:background="#color/backgroundColor">
<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>
<android.support.v7.widget.RecyclerView
android:id="#+id/user_subscriptions"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="12dp"
android:paddingBottom="10dp"
app:layout_behavior="#string/appbar_scrolling_view_behavior"/>
<LinearLayout
android:id="#+id/bottomBox"
android:layout_width="match_parent"
android:layout_height="60dp"
app:layout_behavior="#string/appbar_scrolling_view_behavior
android:background="#android:color/white"
android:orientation="vertical" />
<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_add" />
</android.support.design.widget.CoordinatorLayout>

Your RecyclerView has match_parent in height. so you cannot display anything below in because it will take all the screen height.

I tried too mych on how to force in a recyclerview below a view and i realised its a simple task.
<android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_height="wrap_content"
android:fillViewport="true">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:id="#+id/line1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_gravity="center"
android:padding="16dp">
<Button
android:layout_below="#+id/recycler_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Create Group"
android:layout_gravity="center"
style="#style/Button.Primary"/>
<ImageView
android:id="#+id/image_view_group_image"
android:layout_width="120dp"
android:layout_height="120dp"
android:layout_margin="16dp"
android:layout_gravity="center"
android:scaleType="centerInside"
android:background="#color/colorPrimary"
android:src="#drawable/ic_edit_white_24dp"/>
<TextView
android:layout_below="#+id/image_view_group_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:layout_gravity="center"
android:text="Please add an icon for your group"/>
<android.support.design.widget.TextInputLayout
android:id="#+id/text_input_layout1"
android:layout_below="#+id/image_view_group_image"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:hint="Type your group subject here">
<android.support.design.widget.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:id="#+id/text_input_layout"
android:layout_below="#+id/text_input_layout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:hint="Add Members">
<android.support.design.widget.TextInputEditText
android:id="#+id/text_input_layout_add_members"
android:layout_width="match_parent"
android:drawableRight="#drawable/ic_search_grey_600_24dp"
android:drawableEnd="#drawable/ic_search_grey_600_24dp"
android:layout_height="wrap_content" />
</android.support.design.widget.TextInputLayout>
</LinearLayout>
<android.support.v7.widget.RecyclerView
android:id="#+id/recycler_view"
android:layout_below="#+id/line1"
android:layout_marginTop="16dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_behavior="#string/appbar_scrolling_view_behavior"/>
</RelativeLayout>

You can use NestedScrollView if you want to display RecycleView with other Views like (TextView, Button another recycleView ....) like this example: https://stackoverflow.com/a/63266559/7308789

Related

appbar is not positioning correctly

In my coordinator layout I included another layout which causes AppBarLayout to move to the top and positioned under the status bar,in other words the toolbar height is the half size of it's real height, why is this happening? And also the title of the toolbar is not positioning properly.
<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:id="#+id/ma_main">
<android.support.design.widget.AppBarLayout
android:id="#+id/ma_appbar_layout"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize">
<android.support.v7.widget.Toolbar
android:id="#+id/ma_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="#style/AppTheme.popup"/>
</android.support.design.widget.AppBarLayout>
<include layout="#layout/main_activity_recycler"/>
<android.support.design.widget.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/ma_fab"
app:layout_anchor="#id/ma_recycler_layout"
app:layout_anchorGravity="bottom|end"
android:layout_margin="15dp"
app:fabSize="normal"
android:src="#drawable/pencil"
android:elevation="8dp" />
</android.support.design.widget.CoordinatorLayout>
and included layout
<LinearLayout 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:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:showIn="#layout/activity_main"
android:id="#+id/ma_recycler_layout">
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/ma_recyclerView"
android:visibility="invisible">
</android.support.v7.widget.RecyclerView>
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="2dp"
android:padding="5dp"
android:id="#+id/ma_progressbar"
android:visibility="visible"
android:indeterminate="true"
/></LinearLayout>
make some changes in xml like below ..
<RelativeLayout
android:id="#+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.design.widget.AppBarLayout
android:id="#+id/ma_appbar_layout"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize">
<android.support.v7.widget.Toolbar
android:id="#+id/ma_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="#style/AppTheme.popup" />
</android.support.design.widget.AppBarLayout>
</RelativeLayout>
<include layout="#layout/rl" />
<android.support.design.widget.FloatingActionButton
android:id="#+id/ma_fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="15dp"
android:elevation="8dp"
android:src="#drawable/pencil"
app:fabSize="normal"
app:layout_anchor="#id/ma_recycler_layout"
app:layout_anchorGravity="bottom|end" />
</android.support.design.widget.CoordinatorLayout>
then after recyler view layout like below ..
<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:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
android:id="#+id/ma_recycler_layout">
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/ma_recyclerView"
android:visibility="invisible">
</android.support.v7.widget.RecyclerView>
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
android:padding="5dp"
android:id="#+id/ma_progressbar"
android:visibility="visible"
android:indeterminate="true"
android:layout_centerInParent="true"
/></RelativeLayout>

Last CardView is not showing properly in DrawerLayout

I am trying to display cardViews on drawerLayout something like this:
CardView
But the last CardView is not showing properly.
My cardView.xml code looks like this :
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_margin="10dp"
card_view:cardCornerRadius="4dp"
card_view:cardElevation="10dp"
android:layout_height="wrap_content">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Drinks"
android:id="#+id/posTxt"
android:padding="10dp"
/>
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/image"
android:padding="10dp"
android:src="#drawable/ghost"
android:layout_below="#+id/posTxt"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Name"
android:id="#+id/nameTxt"
android:padding="10dp"
android:textColor="#color/colorGreen"
android:layout_below="#+id/image"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" This is the best drink"
android:id="#+id/descTxt"
android:padding="10dp"
android:layout_below="#+id/nameTxt"
android:layout_alignParentLeft="true"
/>
</RelativeLayout>
</android.support.v7.widget.CardView>
and my activity_main.xml code looks like this:
<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/drawyerLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.hasan.tablayout.MainActivity">
<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<android.support.design.widget.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.v7.widget.Toolbar>
<android.support.design.widget.TabLayout
android:id="#+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabMode="fixed"
app:tabGravity="fill"/>
</android.support.design.widget.AppBarLayout>
<include layout="#layout/content_main"/>
<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>
<android.support.design.widget.NavigationView
android:layout_width="wrap_content"
android:layout_height="match_parent"
app:menu="#menu/navigation_menu"
android:layout_gravity="start"
app:headerLayout="#layout/navigation_header"/>
</android.support.v4.widget.DrawerLayout>
I added card_view:cardCornerRadius , card_view:cardElevation in my xml code. But i don't understand where is my mistake?

FragmentLayout overlapping content

The FraglemtLayout bar is overlapping the content of the page.
i.e. My TabLayout is overlapping the main content of the page.
This is MainActivity layout
<?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/lib/com.example.feelingoodlivinbeta.socialdreams_a1.MainMenuActivity"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="com.example.feelingoodlivinbeta.socialdreams_a1.MainMenuActivity">
<android.support.design.widget.AppBarLayout
android:id="#+id/appbar"
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"
app:popupTheme="#style/AppTheme.PopupOverlay">
</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.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior" >
</android.support.v4.view.ViewPager>
</android.support.design.widget.CoordinatorLayout>
This is model layout contains cardview; I don't know where the problem is located
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="250dp"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="horizontal"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
android:layout_below="#id/fragmantRecycler">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="40dp"
android:orientation="horizontal"
android:weightSum="1">
<LinearLayout
android:layout_width="56dp"
android:layout_height="match_parent"
android:layout_weight="0.06"
android:orientation="horizontal">
<ImageView
android:id="#+id/imageView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="#drawable/socialdreamlogo" />
</LinearLayout>
<TextView
android:id="#+id/nameTxt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="3.67"
android:padding="10dp"
android:text="TextView" />
</LinearLayout>
<ImageView
android:id="#+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"
android:src="#drawable/placeholder" />
</LinearLayout>
</android.support.v7.widget.CardView>
Your problem seems to be related to this line:
xmlns:app="http://schemas.android.com/apk/lib/com.example.feelingoodlivinbeta.socialdreams_a1.MainMenuActivity"
replace it with:
xmlns:app="http://schemas.android.com/apk/res-auto"

Coordinate layout Overlapping container

I am using this layout to load the fragments in side it but when i run that on device it gives look like this.
Below is my code.Any suggest why framelayout is overlapping coordinate layout.
Thanks for help :)
<?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:elevation="7dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.design.widget.CoordinatorLayout xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/cl_root_inner_main"
android:layout_width="match_parent"
android:layout_height="#dimen/toolbar_height"
android:fitsSystemWindows="true">
<android.support.design.widget.AppBarLayout
android:id="#+id/tool_rl"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/colorPrimary"
android:titleTextColor="#color/white"
app:popupTheme="#style/AppTheme.PopupOverlay">
<RelativeLayout
android:id="#+id/buttonsview"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/btnBack"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:padding="#dimen/x10"
android:src="#drawable/ic_arrow_back" />
<TextView
android:id="#+id/fragtitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="#string/select_district"
android:textColor="#color/white"
android:textSize="20sp"
android:visibility="invisible" />
<Button
android:id="#+id/btnPost"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:layout_marginEnd="#dimen/x10"
android:layout_gravity="center_horizontal"
android:text="#string/post"
android:textColor="#color/white"
android:textSize="12sp"
android:theme="#style/blue_button" />
</RelativeLayout>
</android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>
</android.support.design.widget.CoordinatorLayout>
<FrameLayout
android:id="#+id/container"
android:background="#color/orange"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
this is a xml using coordinator layout, I think this will help you
<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="com.software.products.ui.activity.ToolbarUsedActivity"
android:layoutDirection="rtl">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/AppTheme.AppBarOverlay">
<--!just use toolbar here-->
<com.software.android.view.ddToolbar
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_main2" />
</android.support.design.widget.CoordinatorLayout>

Collapsing card view when Recycler View scroll down

How I can put the card below the toolbar and collapse it until it disappear when I scroll down and re open when I scroll up
I am using Xamarin.Android with design libary
Here is my AXML code:
<?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:id="#+id/coordinatorLayoutMainLayoutPublicationsLayout"
android:fitsSystemWindows="true">
<android.support.design.widget.AppBarLayout
android:id="#+id/main.appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true">
<android.support.design.widget.CollapsingToolbarLayout
android:id="#+id/collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
app:layout_scrollFlags="scroll|enterAlways|enterAlwaysCollapsed">
<android.support.v7.widget.CardView
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="#+id/card_view"
android:layout_gravity="center"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cardCornerRadius="4dp"
app:cardElevation="4dp"
app:cardUseCompatPadding="true">
<Button
android:layout_width="match_parent"
android:layout_height="150dp"
android:text="BOBOBOBOBOBOB"
app:layout_scrollFlags="scroll|enterAlways"/>
</android.support.v7.widget.CardView>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.SwipeRefreshLayout
android:id="#+id/swipeContainerPublicationsLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
<android.support.v7.widget.RecyclerView
android:id="#+id/recyclerViewPublicationsLayout"
android:scrollbars="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</android.support.v4.widget.SwipeRefreshLayout>
<android.support.v7.widget.Toolbar
android:id="#+id/toolbarPublicationsLayout"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary" />
<android.support.design.widget.FloatingActionButton
android:id="#+id/fabPublicationsLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:src="#drawable/icon_add_fab"
android:layout_margin="15dp" />
</android.support.design.widget.CoordinatorLayout>
The output view is like this:
Screenshot of the view
After many hours searching I found the solution, make the recyclerview and the cardview inside a NestedScrollView
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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="wrap_content"
android:orientation="vertical"
android:id="#+id/linearLayoutMainLayout">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary" />
<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/coordinatorLayoutMainLayout">
<android.support.v4.widget.SwipeRefreshLayout
android:id="#+id/swipeContainer"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<android.support.v7.widget.CardView
android:id="#+id/card_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cardCornerRadius="4dp"
app:cardElevation="4dp"
app:cardUseCompatPadding="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="8dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textStyle="bold"
android:id="#+id/textView1" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/textView2" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/textView3" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/textView4" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/button" />
</LinearLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.RecyclerView
android:id="#+id/recyclerView"
android:scrollbars="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:nestedScrollingEnabled="false"/>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
</android.support.v4.widget.SwipeRefreshLayout>
<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:src="#drawable/icon_add_fab"
android:layout_margin="15dp"/>
</android.support.design.widget.CoordinatorLayout>
</LinearLayout>

Categories

Resources