Hide Cardview & ImageView inside CollapsingToolbarLayout - android-layout

Whenever I'll scroll my activity, I want toolbar should remain stable and else everything should go below the toolbar. I have used CollapsingToolbarLayout and AppBarLayout, but still I'm not getting proper solution.
Here in this code, CircleImageView and CardView are comming above the toolbar while scrolling.
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<com.google.android.material.appbar.AppBarLayout
android:id="#+id/appbar"
android:layout_width="match_parent"
android:layout_height="#dimen/contact_photo_height"
android:elevation="8dp">
<com.google.android.material.appbar.CollapsingToolbarLayout
android:id="#+id/collapsideToolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
app:contentScrim="?attr/colorAccent"
app:title="back"
app:titleEnabled="false"
>
<ImageView
android:id="#+id/image"
android:layout_width="match_parent"
android:layout_height="200dp"
android:src="#drawable/verify_image"
android:scaleType="centerCrop"
app:layout_collapseMode="parallax"
android:fitsSystemWindows="true"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"/>
<androidx.appcompat.widget.Toolbar
android:id="#+id/tool_bar"
app:title="back"
app:titleTextColor="#color/white"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:contentInsetStartWithNavigation="0dp"
android:theme="#style/ToolbarTheme"
app:layout_collapseMode="pin"/>
</com.google.android.material.appbar.CollapsingToolbarLayout>
</com.google.android.material.appbar.AppBarLayout>
<androidx.cardview.widget.CardView
android:id="#+id/cardView"
android:layout_width="match_parent"
android:layout_height="150dp"
android:layout_marginStart="32dp"
android:layout_marginEnd="32dp"
app:cardElevation="5dp"
app:layout_anchor="#+id/appbar"
app:layout_anchorGravity="bottom|center"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
</androidx.cardview.widget.CardView>
<de.hdodenhof.circleimageview.CircleImageView
android:layout_width="120dp"
android:layout_height="120dp"
android:elevation="8dp"
android:src="#drawable/bg4"
app:layout_anchor="#+id/cardView"
app:layout_anchorGravity="top|center" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>

You are missing one of the most important property app:layout_behavior in card view.
If you want eveything else like cardview, circular ImageView and rest to scroll till toolbar then club them in Relative or LinearLayout and assign app:layout_behavior="#string/appbar_scrolling_view_behavior".
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
<androidx.cardview.widget.CardView
android:id="#+id/cardView"
android:layout_width="match_parent"
android:layout_height="150dp"
android:layout_marginStart="32dp"
android:layout_marginEnd="32dp"
app:cardElevation="5dp"
app:layout_anchor="#+id/appbar"
app:layout_anchorGravity="bottom|center"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
<de.hdodenhof.circleimageview.CircleImageView
android:layout_width="120dp"
android:layout_height="120dp"
android:elevation="8dp"
android:src="#drawable/bg4"
app:layout_anchor="#+id/cardView"
app:layout_anchorGravity="top|center" />
</LinearLayout>
Now, everything will just scroll properly. Hope it helps.

Related

Home Fragment Content is Overlaping my Toolbar and Bottom Navigation View, How can i Solve this?

I am working on an APP where I am using fragments, Now when I am adding content on home fragment and want to show it on the activity main but it is overlapping the toolbar(on activity main) and bottom navigation view. I tried some methods but nothing is working. How can I solve this?? Please GUIDE ME IN THIS MATTER
I am attaching image
My activitymain.xml file
<?xml version="1.0" encoding="utf-8"?>
<androidx.drawerlayout.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:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/drawerlayout"
tools:openDrawer="start"
android:background="#color/white"
tools:context=".MainActivity">
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/ThemeOverlay.AppCompat.Dark">
<androidx.appcompat.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:popupTheme="#style/Theme.AppCompat.Light"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:layout_scrollFlags="scroll|enterAlways"
android:background="#color/reddark"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<ImageView
android:layout_width="150dp"
android:layout_height="50dp"
android:src="#drawable/backsssososos"
android:layout_gravity="center_horizontal"/>
</androidx.appcompat.widget.Toolbar>
<RelativeLayout
android:id="#+id/search_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/toolbar"
android:padding="10dp"
android:background="#color/reddark">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/searchbardesign"
android:drawableLeft="#android:drawable/ic_menu_camera"
android:drawablePadding="22dp"
android:drawableRight="#android:drawable/ic_menu_search"
android:gravity="left|center"
android:hint="Enter City,Colony name..."
android:backgroundTint="#F8F8F8"
android:padding="10dp"
android:textColorHint="#android:color/darker_gray" />
</RelativeLayout>
</com.google.android.material.appbar.AppBarLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<FrameLayout
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="?attr/actionBarSize">
</FrameLayout>
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="#+id/bottom_navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?android:attr/windowBackground"
app:elevation="8dp"
app:labelVisibilityMode="labeled"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:menu="#menu/bottommenu" />
</androidx.constraintlayout.widget.ConstraintLayout>
<com.google.android.material.navigation.NavigationView
android:id="#+id/navmenu"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:itemIconTint="#color/black"
android:theme="#style/NavigationDrawerStyle"
app:headerLayout="#layout/navheader"
app:itemTextColor="#151515"
app:menu="#menu/navigationmenu">
</com.google.android.material.navigation.NavigationView>
</androidx.drawerlayout.widget.DrawerLayout>

android studio: place recycleview on top of Edittext with transparent background

I'm trying to implement a chat activity where the background of the EditText is transparent, so on scrolling up the messages are visible behind the Edittext. But this is the result :
As you can see it is not perfect, I want to be able to scroll a little more to make messages above the edittext completely not behind it!
<androidx.recyclerview.widget.RecyclerView
android:layout_below="#+id/bar_layout"
android:id="#+id/recycle_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layoutManager="LinearLayoutManager"
android:stackFromBottom="true"
android:transcriptMode="alwaysScroll"
android:overScrollMode="never"
/>
<RelativeLayout
android:id="#+id/bottom"
android:layout_width="match_parent"
android:padding="5dp"
android:layout_margin="#dimen/_10sdp"
android:background="#android:color/transparent"
android:layout_alignParentBottom="true"
android:layout_height="wrap_content">
<EditText
android:id="#+id/text_send"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toLeftOf="#+id/btn_send"
android:background="#drawable/sendmessage"
android:hint="Type a message ... "
android:padding="8dp"
android:layout_centerVertical="true"
/>
<ImageButton
android:layout_width="35dp"
android:layout_height="35dp"
android:layout_margin="5dp"
android:id="#+id/btn_send"
android:background="#drawable/ic_paper_plane"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"/>
</RelativeLayout>
Wrap it all in a LinearLayout with orientation="vertical"
<?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"
tools:context=".MainActivity"
android:id="#+id/root">
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/recycle_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:overScrollMode="never"
android:stackFromBottom="true"
android:transcriptMode="alwaysScroll"
app:layoutManager="LinearLayoutManager" />
<RelativeLayout
android:id="#+id/bottom"
android:layout_width="match_parent"
android:padding="5dp"
android:background="#android:color/transparent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true">
<EditText
android:id="#+id/text_send"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toLeftOf="#+id/btn_send"
android:hint="Type a message ... "
android:padding="8dp" />
<ImageButton
android:layout_width="35dp"
android:layout_height="35dp"
android:layout_margin="5dp"
android:id="#+id/btn_send"
android:background="#000000"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"/>
</RelativeLayout>
</RelativeLayout>

custom toolbar after collapsing app bar in android studio

I would like to create a layout like this:
where the search view is in a App bar layout. When it is collapsed I want to change the toolbar like this:
I have searched every where but I was unable to come up with a solution that satisfy me.
thank you.
Use this code.
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.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:layout_height="match_parent">
<com.google.android.material.appbar.AppBarLayout
android:id="#+id/appBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar">
<com.google.android.material.appbar.CollapsingToolbarLayout
android:id="#+id/collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:contentScrim="?attr/colorPrimary"
app:layout_scrollFlags="scroll|enterAlways|snap">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_marginTop="?attr/actionBarSize"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/image"
android:layout_width="match_parent"
android:layout_height="375dp"
android:src="#drawable/yourlogo"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
<androidx.appcompat.widget.Toolbar
android:id="#+id/mToolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light"
app:layout_collapseMode="pin"/>
</com.google.android.material.appbar.CollapsingToolbarLayout>
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_marginBottom="20dp"
android:orientation="horizontal">
<androidx.appcompat.widget.SearchView
android:id="#+id/search_ciew"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginStart="24dp"
android:layout_marginEnd="24dp"
android:background="#fff"
app:iconifiedByDefault="false"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:queryHint="" />
</androidx.constraintlayout.widget.ConstraintLayout>
</com.google.android.material.appbar.AppBarLayout>
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/constraint_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>

Android ViewPager Not working in the NestedScrollView

I want to develop collapsingToolbar with TabLayout. So I was tried with ViewPager with NesteScroolView and CollpasingToolbar, TabLayout Not showing the fragments.
If I remove the "NestedScrollView", then it is working, but if you scroll the fragment page, toolbar collapsing not working. Only CollapsingToolbar components (ImageView and TabLayout) only expanding and collapsing not ViewPager Items.
any Idea please help me.
<?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:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="250dp"
android:id="#+id/appbar"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
android:fitsSystemWindows="true">
<android.support.design.widget.CollapsingToolbarLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/collapsing_toolbar"
android:fitsSystemWindows="true"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<ViewFlipper
android:id="#+id/view_flipper"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:layout_collapseMode="parallax"
>
</ViewFlipper>
<android.support.v7.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:id="#+id/toolbar"
android:layout_gravity="top"
android:background="#color/colorPrimaryDark"
app:layout_collapseMode="pin">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Temples"
/>
</RelativeLayout>
</android.support.v7.widget.Toolbar>
</android.support.design.widget.CollapsingToolbarLayout>
<android.support.design.widget.CollapsingToolbarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_scrollFlags="scroll|enterAlways">
<android.support.design.widget.TabLayout
android:id="#+id/tab_layout"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:layout_gravity="bottom"
android:visibility="visible"
app:tabMode="scrollable"
app:tabGravity="center"
app:layout_scrollFlags="enterAlways"
app:tabTextColor="#ffff11" />
/>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#fefefe"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
<android.support.v4.view.ViewPager
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/viewPager"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
</android.support.v4.view.ViewPager>
</android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>
I want like, scroll the items in the viewpager then should expand and collapse the "CollapsingToolbarLayout"
You can solve this by below code
NestedScrollView scrollView = (NestedScrollView) findViewById (R.id.nest_scrollview);
scrollView.setFillViewport (true);

Colapsing toolbar is not smooth when scrolling down

I have a problem with my collapsing toolbar. When I scroll up (toolbar is colapsing) it scrolls smoothly. Unfurtunately, when i scroll down (toolbar is expanding) scrolling stops waiting for nested scrolling view to get completely scrolled. I guess you will understand it with this GIF:
This is my XML:
<?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:fab="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/vDrawer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/background"
android:fitsSystemWindows="true"
tools:openDrawer="start">
<android.support.design.widget.CoordinatorLayout
android:id="#+id/vCoordinator"
style="#style/Layout.Coordinator"
tools:context="io.stepuplabs.settleup.ui.main.MainActivity">
<io.stepuplabs.settleup.ui.main.StateAwareAppBar
android:id="#+id/vAppBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
android:theme="#style/AppTheme.AppBarOverlay">
<android.support.design.widget.CollapsingToolbarLayout
android:id="#+id/vCollapsingToolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
app:contentScrim="?attr/colorAccent"
app:layout_scrollFlags="scroll|enterAlways|enterAlwaysCollapsed|exitUntilCollapsed|snap">
<ImageView
android:id="#+id/vPlaceholderCircles"
android:layout_width="match_parent"
android:layout_height="296dp"
android:contentDescription="#string/desc_circles"
android:scaleType="centerCrop"
android:src="#drawable/placeholder"
app:layout_collapseMode="none"
/>
<android.support.v7.widget.Toolbar
android:id="#+id/vToolbar"
style="#style/Layout.Toolbar"
android:layout_marginBottom="40dp"
app:layout_collapseMode="pin"
app:layout_collapseParallaxMultiplier="1"
app:popupTheme="#style/AppTheme.PopupOverlay">
<TextView
android:id="#+id/vWhoShouldPayTitle"
android:layout_width="wrap_content"
android:visibility="gone"
android:layout_height="wrap_content"
android:layout_gravity="start"
android:text="#string/app_name"
android:textAppearance="#style/Text.Toolbar" />
</android.support.v7.widget.Toolbar>
<android.support.design.widget.TabLayout
android:id="#+id/vTabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
app:layout_collapseMode="parallax"
app:layout_collapseParallaxMultiplier="0"
app:tabIndicatorColor="#color/white"
app:tabMode="scrollable" />
</android.support.design.widget.CollapsingToolbarLayout>
</io.stepuplabs.settleup.ui.main.StateAwareAppBar>
<android.support.v4.view.ViewPager
android:id="#+id/vViewPager"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior" />
<android.support.v4.widget.ContentLoadingProgressBar
android:id="#+id/vActivityProgress"
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center" />
<com.github.clans.fab.FloatingActionMenu
android:id="#+id/vFloatingActionMenu"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="bottom|end"
android:contentDescription="#string/expense"
android:paddingBottom="10dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
app:layout_behavior="io.stepuplabs.settleup.ui.common.FloatingActionMenuBehavior"
fab:menu_animationDelayPerItem="0"
fab:menu_backgroundColor="#color/dim"
fab:menu_buttonSpacing="6dp"
fab:menu_fab_label="#string/expense"
fab:menu_icon="#drawable/fab_add"
fab:menu_labels_cornerRadius="30dp"
fab:menu_labels_ellipsize="end"
fab:menu_labels_paddingBottom="8dp"
fab:menu_labels_paddingLeft="16dp"
fab:menu_labels_paddingRight="16dp"
fab:menu_labels_paddingTop="8dp"
fab:menu_labels_position="left"
fab:menu_labels_textColor="#color/white"
fab:menu_labels_textSize="14sp">
<com.github.clans.fab.FloatingActionButton
android:id="#+id/vFabTransfer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:contentDescription="#string/transfer"
android:src="#drawable/ic_transfer"
fab:fab_label="#string/transfer"
fab:fab_size="mini" />
</com.github.clans.fab.FloatingActionMenu>
</android.support.design.widget.CoordinatorLayout>
<android.support.design.widget.NavigationView
android:id="#+id/vNavigationDrawer"
android:layout_width="280dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="#color/white"
android:fitsSystemWindows="true"
app:headerLayout="#layout/drawer_header"
app:itemBackground="#drawable/selector_items_background_color"
app:itemIconTint="#color/selector_drawer_items_foreground_color"
app:itemTextColor="#color/selector_drawer_items_foreground_color"
app:menu="#menu/drawer" />
</android.support.v4.widget.DrawerLayout>

Resources