CoordinatorLayout + CollapsingToolbarLayout not setting toolbar when scroll up - java

EDIT: I am not even getting toolbar when i scrolling up. It's not duplicate to suggested question.
I am having issue in getting ImageView and TextView into toolbar when scroll up in CoordinatorLayout. Toolbar not visible when i scroll up in CoordinatorLayout.
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:fitsSystemWindows="false"
android:clipToPadding="false"
android:background="?android:attr/colorBackground"
android:id="#+id/viewuserProfileMain"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<android.support.design.widget.CollapsingToolbarLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:expandedTitleMarginStart="48dp"
app:expandedTitleMarginEnd="64dp"
app:contentScrim="?attr/colorPrimary"
app:layout_scrollFlags="scroll|enterAlways">
<RelativeLayout
android:id="#+id/relativeParent"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="#+id/upCoverPhoto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/redName"/>
<RelativeLayout
android:id="#+id/upDetails"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/diagonal_cut_layerlist"
android:elevation="12dp"
android:translationZ="12dp"
android:layout_marginBottom="20dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="120dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="115dp"
android:layout_marginRight="10dp"
android:gravity="end"
android:orientation="horizontal">
<Button
android:id="#+id/Button_FollowFriends"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="#style/AppButton"
android:text="Follow"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<de.hdodenhof.circleimageview.CircleImageView
android:id="#+id/profilePicture_Cut"
android:layout_width="80dp"
android:layout_height="80dp"
android:src="#drawable/baby"
app:layout_scrollFlags="scroll|enterAlways"
app:civ_border_width="2dp"
app:layout_collapseMode="parallax"
app:layout_collapseParallaxMultiplier="0.7"
app:civ_border_color="#color/primary"
android:layout_marginTop="85dp"
android:layout_marginLeft="15dp"/>
<TextView
android:id="#+id/upUserName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:elevation="12dp"
android:translationZ="12dp"
android:textColor="#color/secondary_text"
android:layout_marginTop="10dp"
android:textSize="28sp"
android:layout_marginLeft="10dp"
android:text="Susan Ledger"/>
<TextView
android:id="#+id/upUserCity"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableLeft="#drawable/home"
android:drawablePadding="5dp"
android:layout_marginTop="5dp"
android:layout_marginLeft="10dp"
android:textSize="18sp"
android:textColor="#color/secondary_text"
android:text="Delhi,India"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="25dp"
android:gravity="center"
android:orientation="horizontal"
android:weightSum="3">
<Button
android:id="#+id/Button_AddFriend"
android:layout_width="0dp"
android:elevation="10dp"
android:translationZ="10dp"
android:layout_height="wrap_content"
style="#style/AppButton"
android:text="Add Friend"
android:layout_weight="1"/>
<Button
android:id="#+id/Button_RejectRequest"
android:layout_width="0dp"
android:layout_height="wrap_content"
style="#style/AppButton"
android:visibility="gone"
android:text="Reject Request"
android:layout_weight="1"/>
<Button
android:id="#+id/Button_MessageFriend"
android:layout_width="0dp"
android:layout_height="wrap_content"
style="#style/AppButton"
android:text="Message"
android:layout_weight="1"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:gravity="center"
android:orientation="horizontal">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="8dp"
android:orientation="vertical"
android:gravity="center">
<TextView
android:id="#+id/FollowersCount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="bold"
android:textColor="#color/primary"
android:textSize="25sp"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="bold"
android:textSize="20sp"
android:text="follower"/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"
android:orientation="vertical"
android:gravity="center">
<TextView
android:id="#+id/FollowingCount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="bold"
android:textColor="#color/primary"
android:textSize="25sp"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="bold"
android:textSize="20sp"
android:text="following"/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"
android:orientation="vertical"
android:gravity="center">
<TextView
android:id="#+id/FriendsCount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="bold"
android:textColor="#color/primary"
android:textSize="25sp"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="bold"
android:textSize="20sp"
android:text="friends"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</RelativeLayout>
</RelativeLayout>
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin" >
</android.support.v7.widget.Toolbar>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/up_NestedScrollView"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="5dp"
android:paddingRight="5dp"
>
<!--To show tab on top of view pager-->
<android.support.design.widget.TabLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabMode="scrollable"
app:tabTextColor="#color/place_autocomplete_prediction_primary_text_highlight"
app:tabSelectedTextColor="#color/primary_text"
app:tabIndicatorColor="#color/primary_light"
android:id="#+id/up_Viewpager_Tab">
</android.support.design.widget.TabLayout>
<android.support.v4.view.ViewPager
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#id/up_Viewpager_Tab"
android:id="#+id/up_Viewpager_ViewPager">
</android.support.v4.view.ViewPager>
</RelativeLayout>
</android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>
In fragment i am setting flag to show transparent status bar
#TargetApi(Build.VERSION_CODES.LOLLIPOP)
public void themeNavAndStatusBar(Activity activity)
{
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP)
return;
Window w = activity.getWindow();
w.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
w.setFlags(
WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION,
WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
w.setFlags(
WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS,
WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
w.setNavigationBarColor(activity.getResources().getColor(android.R.color.transparent));
w.setStatusBarColor(activity.getResources().getColor(android.R.color.transparent));
}

Did you tried changing background & title to toolbar? Check where its visible in your layout.
Try this
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar1"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="#color/colorPrimary"
app:title="Toolbar"
app:layout_collapseMode="pin"
app:popupTheme="#style/AppTheme.PopupOverlay" >
</android.support.v7.widget.Toolbar>
This is what i got
UPATED
Take a reference project in my first comment & moderate based on your needs. Find below code 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"
tools:ignore="RtlHardcoded"
>
<android.support.design.widget.AppBarLayout
android:id="#+id/main.appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
>
<android.support.design.widget.CollapsingToolbarLayout
android:id="#+id/main.collapsing"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_scrollFlags="scroll|exitUntilCollapsed|snap"
>
<ImageView
android:id="#+id/main.imageview.placeholder"
android:layout_width="match_parent"
android:layout_height="450dp"
android:scaleType="centerCrop"
android:src="#drawable/pattern"
android:tint="#11000000"
app:layout_collapseMode="parallax"
app:layout_collapseParallaxMultiplier="0.9"
/>
<FrameLayout
android:id="#+id/main.framelayout.title"
android:layout_width="match_parent"
android:layout_height="300dp"
android:layout_gravity="bottom"
android:orientation="vertical"
app:layout_collapseMode="parallax"
app:layout_collapseParallaxMultiplier="0.3"
>
<LinearLayout
android:id="#+id/main.linearlayout.title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:layout_gravity="center"
android:orientation="vertical"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginStart="20dp"
android:layout_gravity="left"
android:gravity="bottom|center"
android:text="Susan Ledger"
android:textColor="#android:color/white"
android:textSize="30sp"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:layout_marginTop="4dp"
android:layout_marginLeft="20dp"
android:layout_marginStart="20dp"
android:drawableLeft="#drawable/ic_home_black_24dp"
android:drawableStart="#drawable/ic_home_black_24dp"
android:gravity="center"
android:text="Delhi,India"
android:textColor="#android:color/white"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:gravity="center"
android:orientation="horizontal"
android:weightSum="3">
<Button
android:id="#+id/Button_AddFriend"
android:layout_width="0dp"
android:elevation="10dp"
android:translationZ="10dp"
android:layout_height="wrap_content"
android:text="Add Friend"
android:layout_weight="1"/>
<Button
android:id="#+id/Button_RejectRequest"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:visibility="gone"
android:text="Reject Request"
android:layout_weight="1"/>
<Button
android:id="#+id/Button_MessageFriend"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="Message"
android:layout_weight="1"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_marginBottom="20dp"
android:gravity="center"
android:orientation="horizontal">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="8dp"
android:orientation="vertical"
android:gravity="center">
<TextView
android:id="#+id/FollowersCount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="bold"
android:textColor="#android:color/white"
android:textSize="25sp"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="bold"
android:textSize="20sp"
android:textColor="#android:color/white"
android:text="follower"/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"
android:orientation="vertical"
android:gravity="center">
<TextView
android:id="#+id/FollowingCount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="bold"
android:textColor="#color/colorPrimary"
android:textSize="25sp"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="bold"
android:textSize="20sp"
android:text="following"/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"
android:orientation="vertical"
android:gravity="center">
<TextView
android:id="#+id/FriendsCount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="bold"
android:textColor="#color/colorPrimary"
android:textSize="25sp"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="bold"
android:textSize="20sp"
android:text="friends"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</FrameLayout>
</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:scrollbars="none"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
>
<android.support.v7.widget.CardView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="8dp"
app:cardElevation="8dp"
app:contentPadding="16dp"
>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:lineSpacingExtra="8dp"
android:text="#string/lorem"
android:textSize="18sp"
/>
</android.support.v7.widget.CardView>
</android.support.v4.widget.NestedScrollView>
<android.support.v7.widget.Toolbar
android:id="#+id/main.toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="#android:color/transparent"
app:layout_anchor="#id/main.framelayout.title"
app:theme="#style/ThemeOverlay.AppCompat.Dark"
app:title=""
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
>
<Space
android:layout_width="#dimen/image_final_width"
android:layout_height="#dimen/image_final_width"
/>
<TextView
android:id="#+id/main.textview.title"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginLeft="8dp"
android:gravity="center_vertical"
android:layout_weight="1"
android:text="Susan Ledger"
android:textColor="#android:color/white"
android:textSize="20sp"
/>
<Button
android:id="#+id/Button_FollowFriends"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:layout_marginEnd="10dp"
android:layout_gravity="center_vertical"
android:text="Follow"
/>
</LinearLayout>
</android.support.v7.widget.Toolbar>
<de.hdodenhof.circleimageview.CircleImageView
android:layout_width="#dimen/image_width"
android:layout_height="#dimen/image_width"
android:layout_gravity="left"
android:layout_marginLeft="20dp"
android:layout_marginStart="20dp"
android:src="#drawable/profile"
app:civ_border_color="#color/colorAccent"
app:civ_border_width="2dp"
app:finalHeight="#dimen/image_final_width"
app:finalYPosition="2dp"
app:layout_behavior="com.md.collapsingfullview.Activity.AvatarImageBehavior"
app:startHeight="2dp"
app:startToolbarPosition="2dp"
app:startXPosition="2dp"
/>
</android.support.design.widget.CoordinatorLayout>
Add this code to MainActivity.
private void handleToolbarTitleVisibility(float percentage) {
if (percentage >= PERCENTAGE_TO_SHOW_TITLE_AT_TOOLBAR) {
if(!mIsTheTitleVisible) {
startAlphaAnimation(mTitle, ALPHA_ANIMATIONS_DURATION, View.VISIBLE);
mIsTheTitleVisible = true;
}
} else {
if (mIsTheTitleVisible) {
startAlphaAnimation(mTitle, ALPHA_ANIMATIONS_DURATION, View.INVISIBLE);
mIsTheTitleVisible = false;
}
}
if(percentage >= 0.9f)
{
mToolbar.setBackgroundColor(ContextCompat.getColor(getApplicationContext(),R.color.colorPrimary));
}
else
{
mToolbar.setBackgroundColor(ContextCompat.getColor(getApplicationContext(),android.R.color.transparent));
}
}
OUTPUT
At Start
After Scroll

Related

Caused by android.view.InflateException Binary XML file line #9: Binary XML file line #9: Error inflating class android.widget.RelativeLayout

This issue is occuring randomly and I am an intermediate in developing native android applications. This issue ossurs 1% of user engagements within the app. Randomly I can view crash reports of this in firebase crashlytics as follows
Fatal Exception: java.lang.RuntimeException
Unable to start activity ComponentInfo{my.artic.lotcalculatorglobal/my.artic.lotcalculatorglobal.MainActivity}: android.view.InflateException: Binary XML file line #9: Binary XML file line #9: Error inflating class android.widget.RelativeLayout
This is my XML code
`<?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"
android:background="#drawable/alt_background"
android:fitsSystemWindows="true"
tools:context=".MainActivity">
<RelativeLayout
android:id="#+id/titleBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="25dp"
android:layout_marginTop="20dp"
android:layout_marginEnd="20dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="2">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1">
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/app_name"
android:textColor="#color/white"
android:textSize="20sp"
android:textStyle="bold" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/dropMenu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="end">
<RelativeLayout
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_marginStart="20dp"
android:background="#drawable/menu"
android:onClick="showPopup" />
</RelativeLayout>
</LinearLayout>
</RelativeLayout>
<RelativeLayout
android:id="#+id/calculatorLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/titleBar"
android:layout_marginStart="15dp"
android:layout_marginEnd="15dp"
android:layout_marginBottom="80dp">
<androidx.core.widget.NestedScrollView
android:id="#+id/calScroll"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/buttonlayout"
android:layout_alignParentTop="true"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:background="#drawable/layout_background"
android:isScrollContainer="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:id="#+id/fund_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginBottom="5dp"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="start"
android:layout_marginStart="10dp"
android:text="#string/fund"
android:textColor="#color/white"
android:textStyle="bold" />
<EditText
android:id="#+id/fund"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginTop="5dp"
android:background="#drawable/bg_edit_text"
android:hint="#string/input_the_fund_value"
android:inputType="numberDecimal" />
</LinearLayout>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:id="#+id/crypto_info_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="start"
android:layout_marginStart="10dp"
android:text="#string/choose_crypto"
android:textColor="#color/white"
android:textStyle="bold" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginTop="5dp"
android:orientation="horizontal"
android:weightSum="2">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginEnd="5dp"
android:background="#drawable/bg_edit_text">
<Spinner
android:id="#+id/tab"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginEnd="10dp"
android:backgroundTint="#color/white"
android:gravity="center"
android:nestedScrollingEnabled="true"
android:spinnerMode="dropdown" />
</RelativeLayout>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginStart="5dp"
android:background="#drawable/bg_edit_text" />
<Spinner
android:id="#+id/currencyType"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginStart="10dp"
android:backgroundTint="#color/white"
android:gravity="center"
android:nestedScrollingEnabled="true"
android:spinnerMode="dropdown"/>
</RelativeLayout>
</LinearLayout>
</LinearLayout>
</RelativeLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="start"
android:layout_marginStart="10dp"
android:text="#string/service_charge"
android:textColor="#color/white"
android:textStyle="bold" />
<EditText
android:id="#+id/s_charge"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginTop="5dp"
android:background="#drawable/bg_edit_text"
android:hint="#string/input_the_service_charge_value"
android:inputType="numberDecimal" />
</LinearLayout>
</RelativeLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="start"
android:layout_marginStart="10dp" />
<EditText
android:id="#+id/lockUpDeposit"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginTop="5dp"
android:background="#drawable/bg_edit_text"
android:hint="#string/input_the_currency_value"
android:inputType="numberDecimal"
android:paddingStart="20dp" />
</LinearLayout>
</RelativeLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="10dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="start"
android:text="#string/range"
android:textColor="#color/white"
android:textStyle="bold" />
<EditText
android:id="#+id/range"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginTop="5dp"
android:background="#drawable/bg_edit_text"
android:hint="#string/input_the_range_value"
android:inputType="numberDecimal"
android:paddingStart="10dp"
android:textColorHint="#color/light_green"
android:visibility="gone" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_centerInParent="true"
android:layout_centerVertical="true"
android:layout_marginTop="5dp"
android:layout_toStartOf="#+id/seek_value"
android:orientation="vertical">
<SeekBar
android:id="#+id/seekBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="-15dp"
android:max="15"
android:min="5"
android:progress="15" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="15dp"
android:weightSum="2">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="start"
android:text="0.5" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="end"
android:text="1.5"/>
</LinearLayout>
</LinearLayout>
<TextView
android:id="#+id/seek_value"
android:layout_width="45dp"
android:layout_height="30dp"
android:layout_alignParentEnd="true"
android:layout_centerInParent="true"
android:background="#drawable/bg_edit_text"
android:gravity="center"
android:text="1.5" />
</RelativeLayout>
</LinearLayout>
</RelativeLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="25dp"
android:layout_marginBottom="5dp"
android:weightSum="2">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="start"
android:layout_marginStart="10dp"
android:text="#string/lot" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="5dp"
android:animateLayoutChanges="true"
android:orientation="horizontal">
<TextView
android:id="#+id/lot"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/bg_white"
android:padding="10dp"
android:text="0.0" />
<RelativeLayout
android:id="#+id/copy"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_gravity="center_vertical"
android:layout_marginStart="5dp"
android:background="#drawable/icon_copy"
android:onClick="onClick"
tools:ignore="SpeakableTextPresentCheck,TouchTargetSizeCheck" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:animateLayoutChanges="true"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="#string/s_charge" />
<TextView
android:id="#+id/charge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:animateLayoutChanges="true"
android:background="#drawable/bg_white"
android:text="0.0" />
</LinearLayout>
</RelativeLayout>
</LinearLayout>
</RelativeLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:layout_marginBottom="5dp"
android:animateLayoutChanges="true"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="#string/profit_range"/>
<TextView
android:id="#+id/profit_range"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="5dp"
android:background="#drawable/bg_white"
android:padding="10dp"
android:text="0.0" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:gravity="center"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="#string/gross_profit" />
<TextView
android:id="#+id/gross_profit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text=" 0.0" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>
</LinearLayout>
</androidx.core.widget.NestedScrollView>
<RelativeLayout
android:id="#+id/buttonlayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:animateLayoutChanges="true"
android:orientation="vertical"
android:weightSum="2">
<androidx.appcompat.widget.AppCompatButton
android:id="#+id/calculate"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_gravity="center"
android:layout_weight="1"
android:background="#drawable/bg_button_main"
android:onClick="onClick" />
<androidx.appcompat.widget.AppCompatButton
android:id="#+id/clear"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_gravity="center"
android:background="#drawable/bg_button_main"
android:onClick="onClick" />
<androidx.appcompat.widget.AppCompatButton
android:id="#+id/clearAll"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_gravity="center"
android:background="#drawable/bg_button_main"
android:onClick="onClick" />
</LinearLayout>
</RelativeLayout>
</RelativeLayout>
<com.google.android.gms.ads.AdView xmlns:ads="http://schemas.android.com/apk/res-auto"
android:id="#+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</RelativeLayout>`

Pin ImageView and headed view in the top while scrolling and make the other view as scrollable in android

I need to pin the image while scrolling with the headed section and need to scroll other thing in the screen.
Here I need the header as fixed while scrolling and the half of the fill 2 image shown while scrolling.
Now the header actionsof on click are not working after addding nestedScrollView.
Also the nested view is overlapping with the above view while scrolling
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:id="#+id/coordinator"
style="#style/CoordinatorLayout"
android:background="red"
tools:ignore="RtlHardcoded">
<com.google.android.material.appbar.AppBarLayout
android:id="#+id/layout_app_bar"
style="#style/Collapsing.AppBarLayout"
android:background="blue">
<com.google.android.material.appbar.CollapsingToolbarLayout
android:id="#+id/layout_collapsing_toolbar"
style="#style/Collapsing.CollapsingToolbarLayout"
android:layout_height="427dp">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="#dimen/spacing_x5"
android:background="green"
android:gravity="center"
android:id="#+id/header_view"
android:visibility="visible"
android:orientation="horizontal">
<ImageView
android:id="#+id/back"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="#drawable/black"
android:clickable="true"
android:contentDescription="#string/back"
android:src="#drawable/ic_arrow_left"/>
<TextView
android:id="#+id/header_my_home"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:clickable="true"
android:textSize="18dp"
android:gravity="center"
android:textColor="#color/white"
android:scaleType="centerInside"
android:text="MY Home Feed"/>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/label"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:clickable="true"
android:orientation="vertical"
>
<TextView
android:id="#+id/label1"
android:layout_width="80dp"
android:layout_height="48dp"
android:gravity="center"
android:visibility="visible"
android:clickable="true"
android:textSize="18dp"
android:textColor="#707070"
android:text="label1"
/>
</RelativeLayout>
</LinearLayout>
<ImageView
android:id="#id/iv_background"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:layout_marginTop="50dp"
android:adjustViewBounds="true"
android:src="#drawable/image" />
<ImageView
android:id="#id/fill_1"
android:src="#drawable/fill_1"
android:scaleType="fitStart"
android:layout_marginTop="148dp"
android:layout_marginLeft="-20dp"
android:layout_marginRight="-20dp"
android:layout_centerHorizontal="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<ImageView
android:id="#id/fill_2"
android:src="#drawable/fill_2"
android:scaleType="fitCenter"
android:layout_marginTop="128dp"
android:layout_marginLeft="-20dp"
android:layout_marginRight="-20dp"
android:layout_marginBottom="-30dp"
android:layout_centerHorizontal="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</FrameLayout>
</com.google.android.material.appbar.CollapsingToolbarLayout>
<androidx.appcompat.widget.Toolbar
android:id="#+id/toolbar"
style="#style/Collapsing.Toolbar" />
<View
android:id="#+id/divider"
style="#style/Collapsing.Divider" />
</com.google.android.material.appbar.AppBarLayout>
<androidx.core.widget.NestedScrollView android:layout_height="wrap_content"
android:layout_width="wrap_content" android:id="#+id/nested_scroll">
<LinearLayout
android:layout_width="match_parent"
android:layout_gravity="center"
android:orientation="vertical"
android:layout_marginTop="500dp"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#color/white"
android:textSize="27dp"
android:layout_marginTop="5dp"
android:layout_gravity="center"
>
</TextView>
<androidx.recyclerview.widget.RecyclerView
android:layout_width="match_parent"
android:layout_gravity="center"
android:layout_marginTop="30dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:id="#+id/recycler_view"
android:orientation="horizontal"
android:layout_height="wrap_content">
</androidx.recyclerview.widget.RecyclerView>
<View style="#style/Divider.Horizontal.Gray"
android:layout_width="match_parent"
android:layout_marginTop="#dimen/spacing_x2"
android:layout_marginBottom="#dimen/spacing_x2"
android:layout_height="2dp"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_gravity="center"
android:orientation="horizontal"
android:layout_marginLeft="20dp"
android:visibility="gone"
android:layout_marginRight="20dp"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#color/white"
android:textSize="21sp"
android:layout_weight="1"
android:layout_gravity="left"
>
</TextView>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#color/white"
android:textSize="14sp"
android:layout_weight="0.1"
android:layout_gravity="right"
android:text="lanl">
</TextView>
</LinearLayout>
<androidx.recyclerview.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/recycler_view"
android:visibility="gone"
android:orientation="vertical"
>
</androidx.recyclerview.widget.RecyclerView>
<LinearLayout
android:layout_width="match_parent"
android:layout_gravity="center"
android:orientation="horizontal"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#color/white"
android:textSize="21sp"
android:layout_weight="1"
>
</TextView>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#color/white"
android:textSize="14sp"
android:layout_weight="0.1"
android:layout_gravity="right"
>
</TextView>
</LinearLayout>
<androidx.recyclerview.widget.RecyclerView
android:layout_width="wrap_content"
android:layout_gravity="center"
android:layout_margin="20dp"
android:id="#+id/recycler_view1"
android:orientation="horizontal"
android:layout_height="wrap_content">
</androidx.recyclerview.widget.RecyclerView>
<View style="#style/Divider.Horizontal.Gray"
android:layout_width="match_parent"
android:layout_marginTop="#dimen/spacing_x2"
android:layout_marginBottom="#dimen/spacing_x2"
android:layout_height="2dp"/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"android:visibility="visible">
<LinearLayout
android:layout_width="match_parent"
android:layout_gravity="center"
android:orientation="horizontal"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_height="wrap_content"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#color/white"
android:layout_weight="1"
android:layout_gravity="left"
>
</TextView>
<ImageView
android:layout_width="30dp"
android:layout_height="27dp"
android:layout_weight="0.1"
android:layout_gravity="right"
>
</ImageView>
</LinearLayout>
<com.google.android.material.tabs.TabLayout
android:id="#+id/tab_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignTop="#id/search"
android:layout_marginTop="15dp"
android:background="#color/dark_blue"
app:tabGravity="fill"
app:tabIndicatorColor="#color/blue_light"
app:tabIndicatorHeight="5dp"
app:tabMode="scrollable" />
<com.finaonation.utility.NonScrollableViewPager
android:id="#+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
<androidx.recyclerview.widget.RecyclerView
android:layout_width="match_parent"
android:layout_gravity="center"
android:layout_margin="20dp"
android:orientation="horizontal"
android:layout_height="wrap_content">
</androidx.recyclerview.widget.RecyclerView>
<LinearLayout
android:layout_width="match_parent"
android:layout_gravity="center"
android:orientation="horizontal"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginBottom="20dp"
android:layout_height="wrap_content"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#color/white"
android:layout_weight="1"
android:layout_gravity="left"
android:textSize="16sp"
</TextView>
<ImageView
android:layout_width="30dp"
android:layout_height="27dp"
android:layout_weight="0.1"
android:layout_gravity="right"
>
</ImageView>
</LinearLayout>
<View style="#style/Divider.Horizontal.Gray"
android:layout_width="match_parent"
android:layout_marginTop="#dimen/spacing_x2"
android:layout_marginBottom="#dimen/spacing_x2"
android:layout_height="2dp"
android:id="#+id/divider"
android:visibility="visible"/>
</LinearLayout>
<androidx.recyclerview.widget.RecyclerView
android:layout_width="match_parent"
android:layout_gravity="center"
android:layout_margin="20dp"
android:id="#+id/recycler_view_m"
android:orientation="horizontal"
android:layout_height="wrap_content">
</androidx.recyclerview.widget.RecyclerView>
</LinearLayout>
</androidx.core.widget.NestedScrollView>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
<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.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.design.widget.CollapsingToolbarLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<!-- HEADER -->
<RelativeLayout
...
app:layout_collapseMode="parallax">
.....
</RelativeLayout>
<android.support.v7.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin" />
</android.support.design.widget.CollapsingToolbarLayout>
<!-- IF YOU WANT TO KEEP "Choose Item" always on top of the RecyclerView, put this TextView here
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:text="choose item" />
-->
</android.support.design.widget.AppBarLayout>
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior" />
</android.support.design.widget.CoordinatorLayout>

how to set content of textview to toolbar when scrolling in Collapsingtoolbarlayout?

I have an activity with CollapsingToolbarLayout and with a lot of widgets in NestedScrollingview that I use for details of products ... I want when scrolling the activity to up the title that is below the slider goes to the toolbar and show on the toolbar... Must I add more attributes in .xml or write code in .java?
activity.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"
android:background="#color/bg_main"
tools:context=".DetailsActivity">
<android.support.design.widget.AppBarLayout
android:id="#+id/app_bar_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
android:fitsSystemWindows="true">
<android.support.design.widget.CollapsingToolbarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
app:contentScrim="?attr/colorPrimary"
app:expandedTitleTextAppearance="#android:color/transparent"
android:fitsSystemWindows="true">
<com.daimajia.slider.library.SliderLayout
android:id="#+id/sliderdetails"
android:layout_width="match_parent"
android:layout_height="300dp"
/>
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light"
app:layout_collapseMode="pin">
<ImageView
android:id="#+id/img_cardtool"
android:layout_width="25dp"
android:layout_height="35dp"
android:src="#drawable/ic_shop"
android:layout_marginLeft="20dp"/>
</android.support.v7.widget.Toolbar>
</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:clipToPadding="false"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cardElevation="0dp"
android:layout_marginBottom="0dp"
app:cardUseCompatPadding="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/bg_caption_details"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="6dp"
android:layout_gravity="left">
<ImageView
android:id="#+id/img_sharedetail"
android:layout_width="25dp"
android:layout_height="35dp"
android:src="#drawable/ic_shareb"
android:layout_marginLeft="5dp"
/>
<ImageView
android:id="#+id/img_notificationdetail"
android:layout_width="25dp"
android:layout_height="35dp"
android:src="#drawable/ic_notification"
android:layout_marginLeft="20dp"
/>
<ImageView
android:id="#+id/img_bookmarddetail"
android:layout_width="25dp"
android:layout_height="35dp"
android:src="#drawable/ic_fav"
android:layout_marginLeft="20dp"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="5dp">
<TextView
android:id="#+id/txtcaptiondetail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:hint=" عنوان اصلی محصول"
android:textSize="16sp"
android:textStyle="bold"
android:textColor="#color/black"/>
<TextView
android:id="#+id/txtcaptiondescdetail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:hint=" عنوان دوم محصول"
android:textSize="14sp"
android:layout_marginTop="5dp"
android:textColor="#color/twotitle"/>
</LinearLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="50dp">
<android.support.v7.widget.CardView
android:id="#+id/cardView"
android:layout_width="150dp"
android:layout_height="35dp"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:layout_marginTop="8dp"
android:foreground="?attr/selectableItemBackground"
android:background="#drawable/cardviewrounded"
android:clickable="true"
android:padding="6dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#+id/cardView2"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.517">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<ImageView
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_centerVertical="true"
android:layout_marginLeft="5dp"
android:layout_toRightOf="#id/txtdesc"
android:src="#drawable/ic_contet" />
<TextView
android:id="#+id/txtdesc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="مشخصات"
android:textStyle="bold" />
</RelativeLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:id="#+id/cardView2"
android:layout_width="150dp"
android:layout_height="35dp"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:foreground="?attr/selectableItemBackground"
android:clickable="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="#+id/cardView"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_centerVertical="true"
android:layout_marginLeft="5dp"
android:layout_toRightOf="#id/txtrespo"
android:src="#drawable/ic_response" />
<TextView
android:id="#+id/txtrespo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_gravity="center"
android:text="نظرات کاربران"
android:textStyle="bold" />
</RelativeLayout>
</android.support.v7.widget.CardView>
</android.support.constraint.ConstraintLayout>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>

Toolbar back arrow with icon

How to display icon with back arrow in android toolbar like WhatsApp ?
I would like to reduce the space between the photo and the back arrow.
How can I reduce space?
I have:
ChatActivity.java: the layout (which has only one view) is replaced with ChatFragment.java. Moreover, the toolbar is replaced here with fragment_chat_toolbar.xml
ChatFragment.java: here the inputs, the emojis, the files etc. are managed
Thanks.
My toolbar chat
fragment_chat.xml
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/layout_chat"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<android.support.v7.widget.RecyclerView
android:id="#+id/fragment_chat_recycler_view"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_weight="1"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginBottom="4dp"
android:layout_marginLeft="4dp"
android:layout_marginRight="4dp"
android:gravity="center" >
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="horizontal"
android:layout_marginEnd="4dp"
android:background="#drawable/incoming_message"
android:baselineAligned="false">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingBottom="2dp"
android:paddingStart="2dp"
android:paddingEnd="4dp" >
<ImageView
android:id="#+id/image_view_emoji"
android:layout_width="28dp"
android:layout_height="28dp"
android:layout_marginStart="6dp"
android:layout_gravity="center"
android:contentDescription="#string/emoji_button"
android:src="#mipmap/ic_emoji"
android:tint="#color/total_black" />
<com.vanniktech.emoji.EmojiEditText
android:id="#+id/message_box_emoji"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="8dp"
android:layout_weight="1"
android:background="#color/incomingColor"
android:hint="#string/send_message"
app:emojiSize="26sp"/>
<ImageView
android:id="#+id/image_view_camera"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="6dp"
android:layout_gravity="center"
android:contentDescription="#string/camera_button"
android:src="#mipmap/ic_camera"
android:tint="#color/total_black" />
</LinearLayout>
</LinearLayout>
<android.support.design.widget.FloatingActionButton
android:id="#+id/float_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end|bottom"
android:src="#mipmap/ic_voice_recorder"
android:tint="#color/white"
app:backgroundTint="#color/colorPrimary"
app:elevation="0dp"
app:fabSize="mini"/>
</LinearLayout>
</LinearLayout>
fragment_chat_toolbar.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:fresco="http://schemas.android.com/apk/res-auto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:clipChildren="false" >
<com.facebook.drawee.view.SimpleDraweeView
android:id="#+id/profile_photo"
android:layout_width="50dp"
android:layout_height="50dp"
fresco:failureImage="#drawable/default_profile"
fresco:placeholderImage="#drawable/default_profile"
fresco:roundAsCircle="true" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginStart="4dp"
android:gravity="start"
android:orientation="vertical" >
<TextView
android:id="#+id/chat_title_text_view"
android:layout_width="wrap_content"
android:textSize="16sp"
android:layout_height="wrap_content"
android:maxLines="1"
android:textColor="#color/white" />
<TextView
android:id="#+id/chat_subtitle_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxLines="1"
android:textColor="#color/white" />
</LinearLayout>
Make Custom Toolbar as you like. Change your layout in RelativeLayout
<android.support.v7.widget.Toolbar
android:id="#+id/toolBar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:contentInsetEnd="0dp"
app:contentInsetLeft="0dp"
app:contentInsetRight="0dp"
app:contentInsetStart="0dp"
app:popupTheme="#style/AppTheme.PopupOverlay">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="#+id/llLeft"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:background="#drawable/transparent_layout_background"
android:clickable="true"
android:focusable="true"
android:gravity="center"
android:padding="10dp">
<ImageView
android:id="#+id/ivLeft"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:src="#drawable/ic_action_menu" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_toEndOf="#+id/llLeft"
android:layout_toLeftOf="#+id/llRight"
android:layout_toRightOf="#+id/llLeft"
android:layout_toStartOf="#+id/llRight"
android:gravity="center">
<TextView
android:id="#+id/tvTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:fontFamily="#font/roboto_bold"
android:lines="1"
android:text="asdf"
android:textColor="#color/colorWhite"
android:textSize="18sp" />
</LinearLayout>
<LinearLayout
android:id="#+id/llRight"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:background="#drawable/transparent_layout_background"
android:clickable="true"
android:focusable="true"
android:gravity="center"
android:padding="10dp">
<ImageView
android:id="#+id/ivRight"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:src="#drawable/ic_action_search" />
</LinearLayout>
</RelativeLayout>
</android.support.v7.widget.Toolbar>

How to add Layout on top of another Layout?

My English is poor. So I threw off the video. I think any programmer looking at this will understand the reason. Thank you in advance
I want to learn how to use ReleaseativeLayout correctly, because ConstainLayout is very buggy. Even using it in Android Studio Canary.
So I'm using ReleativeLayout and LineartLayout now. These are the most effective ViewGroup. I thought. But it turned out all wrong
XML Code
<RelativeLayout
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:gravity="center"
android:theme="#style/ThemeOverlay.AppCompat.Dark"
android:background="#drawable/login_faggot">
<TextView
android:gravity="center_horizontal"
android:layout_above="#+id/plsLogin"
android:text="Welcome."
android:textSize="18sp"
android:textColor="#color/white"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<TextView
android:layout_marginBottom="25dp"
android:textSize="16sp"
android:textColor="#color/grayBg"
android:gravity="center_horizontal"
android:id="#+id/plsLogin"
android:layout_above="#+id/editLogin"
android:text="Please Login."
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<TextView
android:background="#color/white"
android:layout_alignLeft="#+id/editLogin"
android:layout_alignBaseline="#+id/editLogin"
android:layout_marginStart="50dp"
android:layout_width="1dp"
android:layout_height="wrap_content"/>
<TextView
android:background="#color/white"
android:layout_alignLeft="#+id/editPass"
android:layout_alignBaseline="#+id/editPass"
android:layout_marginStart="50dp"
android:layout_width="1dp"
android:layout_height="wrap_content"/>
<EditText
android:paddingStart="20dp"
android:drawableStart="#drawable/ic_mail_white_24dp"
android:drawablePadding="15dp"
android:hint="#string/user_name"
android:layout_alignStart="#+id/buttonLogin"
android:layout_alignEnd="#+id/buttonLogin"
android:layout_above="#+id/editPass"
android:id="#+id/editLogin"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<EditText
android:drawableStart="#drawable/ic_lock_white_24dp"
android:paddingStart="20dp"
android:drawablePadding="15dp"
android:hint="#string/password"
android:layout_alignEnd="#+id/buttonLogin"
android:layout_alignStart="#+id/buttonLogin"
android:layout_above="#+id/linearLayout"
android:id="#+id/editPass"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<LinearLayout
android:layout_marginStart="15dp"
android:id="#+id/linearLayout"
android:layout_above="#+id/buttonLogin"
android:layout_alignEnd="#+id/buttonLogin"
android:layout_alignStart="#+id/buttonLogin"
android:layout_width="match_parent"
android:layout_marginBottom="50dp"
android:layout_height="wrap_content">
<CheckBox
style="#style/Widget.AppCompat.CompoundButton.RadioButton"
android:id="#+id/radioButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Remember Me"
android:paddingStart="15dp"
android:textColor="#color/white"/>
<TextView
android:visibility="invisible"
android:id="#+id/textView"
android:textColor="#color/white"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="end"
android:text="Forgot Password"/>
</LinearLayout>
<android.support.v7.widget.AppCompatButton
android:id="#+id/buttonLogin"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="30dp"
android:layout_marginStart="30dp"
android:background="#drawable/button_round_corner"
app:backgroundTint="#color/colorOrangeUsSite"
android:text="#string/login"
android:textColor="#color/white"/>
<FrameLayout
android:background="#color/black"
android:alpha="0.8"
android:visibility="gone"
android:id="#+id/layoutProgressBar"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ProgressBar
android:theme="#style/ProgressBar"
android:layout_gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</FrameLayout>
</RelativeLayout>
Just add one more Relative Layout below of your parent layout and set Gravity to it
<RelativeLayout
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:theme="#style/ThemeOverlay.AppCompat.Dark"
android:background="#drawable/login_faggot">
<RelativeLayout
android:layout_width="match_parent"
android:gravity="center"
android:layout_height="match_parent">
<TextView
android:gravity="center_horizontal"
android:layout_above="#+id/plsLogin"
android:text="Welcome."
android:textSize="18sp"
android:textColor="#color/white"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<TextView
android:layout_marginBottom="25dp"
android:textSize="16sp"
android:textColor="#color/grayBg"
android:gravity="center_horizontal"
android:id="#+id/plsLogin"
android:layout_above="#+id/editLogin"
android:text="Please Login."
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<TextView
android:background="#color/white"
android:layout_alignLeft="#+id/editLogin"
android:layout_alignBaseline="#+id/editLogin"
android:layout_marginStart="50dp"
android:layout_width="1dp"
android:layout_height="wrap_content"/>
<TextView
android:background="#color/white"
android:layout_alignLeft="#+id/editPass"
android:layout_alignBaseline="#+id/editPass"
android:layout_marginStart="50dp"
android:layout_width="1dp"
android:layout_height="wrap_content"/>
<EditText
android:paddingStart="20dp"
android:drawableStart="#drawable/ic_mail_white_24dp"
android:drawablePadding="15dp"
android:hint="#string/user_name"
android:layout_alignStart="#+id/buttonLogin"
android:layout_alignEnd="#+id/buttonLogin"
android:layout_above="#+id/editPass"
android:id="#+id/editLogin"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<EditText
android:drawableStart="#drawable/ic_lock_white_24dp"
android:paddingStart="20dp"
android:drawablePadding="15dp"
android:hint="#string/password"
android:layout_alignEnd="#+id/buttonLogin"
android:layout_alignStart="#+id/buttonLogin"
android:layout_above="#+id/linearLayout"
android:id="#+id/editPass"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<LinearLayout
android:layout_marginStart="15dp"
android:id="#+id/linearLayout"
android:layout_above="#+id/buttonLogin"
android:layout_alignEnd="#+id/buttonLogin"
android:layout_alignStart="#+id/buttonLogin"
android:layout_width="match_parent"
android:layout_marginBottom="50dp"
android:layout_height="wrap_content">
<CheckBox
style="#style/Widget.AppCompat.CompoundButton.RadioButton"
android:id="#+id/radioButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Remember Me"
android:paddingStart="15dp"
android:textColor="#color/white"/>
<TextView
android:visibility="invisible"
android:id="#+id/textView"
android:textColor="#color/white"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="end"
android:text="Forgot Password"/>
</LinearLayout>
<android.support.v7.widget.AppCompatButton
android:id="#+id/buttonLogin"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="30dp"
android:layout_marginStart="30dp"
android:background="#drawable/button_round_corner"
app:backgroundTint="#color/colorOrangeUsSite"
android:text="#string/login"
android:textColor="#color/white"/>
</RelativeLayout>
<FrameLayout
android:background="#color/black"
android:alpha="0.8"
android:visibility="gone"
android:id="#+id/layoutProgressBar"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ProgressBar
android:theme="#style/ProgressBar"
android:layout_gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</FrameLayout>
Only parent layout height and width would match parent instead of a child.
you've have entered FrameLayout height="match_parent"
you've to implement like this.
<RelativeLayout
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:gravity="center"
android:theme="#style/ThemeOverlay.AppCompat.Dark"
android:background="#drawable/login_faggot">
<TextView
android:gravity="center_horizontal"
android:layout_above="#+id/plsLogin"
android:text="Welcome."
android:textSize="18sp"
android:textColor="#color/white"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<TextView
android:layout_marginBottom="25dp"
android:textSize="16sp"
android:textColor="#color/grayBg"
android:gravity="center_horizontal"
android:id="#+id/plsLogin"
android:layout_above="#+id/editLogin"
android:text="Please Login."
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<TextView
android:background="#color/white"
android:layout_alignLeft="#+id/editLogin"
android:layout_alignBaseline="#+id/editLogin"
android:layout_marginStart="50dp"
android:layout_width="1dp"
android:layout_height="wrap_content"/>
<TextView
android:background="#color/white"
android:layout_alignLeft="#+id/editPass"
android:layout_alignBaseline="#+id/editPass"
android:layout_marginStart="50dp"
android:layout_width="1dp"
android:layout_height="wrap_content"/>
<EditText
android:paddingStart="20dp"
android:drawableStart="#drawable/ic_mail_white_24dp"
android:drawablePadding="15dp"
android:hint="#string/user_name"
android:layout_alignStart="#+id/buttonLogin"
android:layout_alignEnd="#+id/buttonLogin"
android:layout_above="#+id/editPass"
android:id="#+id/editLogin"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<EditText
android:drawableStart="#drawable/ic_lock_white_24dp"
android:paddingStart="20dp"
android:drawablePadding="15dp"
android:hint="#string/password"
android:layout_alignEnd="#+id/buttonLogin"
android:layout_alignStart="#+id/buttonLogin"
android:layout_above="#+id/linearLayout"
android:id="#+id/editPass"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<LinearLayout
android:layout_marginStart="15dp"
android:id="#+id/linearLayout"
android:layout_above="#+id/buttonLogin"
android:layout_alignEnd="#+id/buttonLogin"
android:layout_alignStart="#+id/buttonLogin"
android:layout_width="match_parent"
android:layout_marginBottom="50dp"
android:layout_height="wrap_content">
<CheckBox
style="#style/Widget.AppCompat.CompoundButton.RadioButton"
android:id="#+id/radioButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Remember Me"
android:paddingStart="15dp"
android:textColor="#color/white"/>
<TextView
android:visibility="invisible"
android:id="#+id/textView"
android:textColor="#color/white"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="end"
android:text="Forgot Password"/>
</LinearLayout>
<android.support.v7.widget.AppCompatButton
android:id="#+id/buttonLogin"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="30dp"
android:layout_marginStart="30dp"
android:background="#drawable/button_round_corner"
app:backgroundTint="#color/colorOrangeUsSite"
android:text="#string/login"
android:textColor="#color/white"/>
<FrameLayout
android:background="#color/black"
android:alpha="0.8"
android:visibility="gone"
android:id="#+id/layoutProgressBar"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ProgressBar
android:theme="#style/ProgressBar"
android:layout_gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</FrameLayout>
</RelativeLayout>

Categories