I have a problem I want the orange cardView on the top to be like this:
and when the user Scorll I have to make this orange card scroll as well
but I used coordinate layout with anchor for the card
I've to make it invisible when the user scrolls away a little bit but I have this:
my question is how to make this orange cardview to stay and scroll with other layout elements?
my xml file is:
<?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: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="wrap_content"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:elevation="0dp">
<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_collapseMode="pin"
app:popupTheme="#style/AppTheme.PopupOverlay">
</android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>
<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v4.widget.NestedScrollView
android:id="#+id/nested_scroll_view"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v7.widget.CardView
android:id="#+id/profile_card"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="60dp"
android:layout_marginLeft="#dimen/app_margin"
android:layout_marginRight="#dimen/app_margin"
android:layout_marginBottom="#dimen/app_margin"
app:elevation="3dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/username"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="bold"
android:textAppearance="#style/Base.TextAppearance.AppCompat.Medium"
android:layout_marginTop="60dp"
android:layout_marginBottom="#dimen/app_margin"
android:text="Mark Davis"
android:layout_centerHorizontal="true"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_below="#id/username"
android:text="IT consuler"
android:layout_marginBottom="#dimen/app_margin"
android:id="#+id/textView" />
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="#+id/textView"
android:layout_marginTop="15dp"
android:layout_weight="1"
android:elevation="3dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Personal Information"
android:textAppearance="#style/Base.TextAppearance.AppCompat.Medium" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</android.support.v7.widget.CardView>
</RelativeLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_margin="#dimen/app_margin"
android:layout_height="0dp"
android:layout_weight="1">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="#style/Base.TextAppearance.AppCompat.Medium"
android:text="Personal Inforamtion"
android:elevation="3dp"
android:textStyle="bold"
android:layout_margin="#dimen/app_margin"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="User Name"
android:textStyle="bold"
android:textSize="16sp"
android:textColor="#color/colorAccent"
android:layout_marginBottom="#dimen/app_margin"
android:layout_marginLeft="#dimen/app_margin"
android:textAppearance="#style/TextAppearance.AppCompat.Small"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="User Name"
android:layout_marginLeft="32dp"
android:layout_marginRight="#dimen/app_margin"
android:layout_marginBottom="#dimen/app_margin"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Email"
android:textStyle="bold"
android:textSize="16sp"
android:textColor="#color/colorAccent"
android:layout_marginBottom="#dimen/app_margin"
android:layout_marginLeft="#dimen/app_margin"
android:textAppearance="#style/TextAppearance.AppCompat.Small"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Email"
android:layout_marginLeft="32dp"
android:layout_marginRight="#dimen/app_margin"
android:layout_marginBottom="#dimen/app_margin"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Display name"
android:textStyle="bold"
android:textSize="16sp"
android:textColor="#color/colorAccent"
android:layout_marginBottom="#dimen/app_margin"
android:layout_marginLeft="#dimen/app_margin"
android:textAppearance="#style/TextAppearance.AppCompat.Small"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Display name"
android:layout_marginLeft="32dp"
android:layout_marginRight="#dimen/app_margin"
android:layout_marginBottom="#dimen/app_margin"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Password"
android:textStyle="bold"
android:textSize="16sp"
android:textColor="#color/colorAccent"
android:layout_marginBottom="#dimen/app_margin"
android:layout_marginLeft="#dimen/app_margin"
android:textAppearance="#style/TextAppearance.AppCompat.Small"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Password"
android:layout_marginLeft="32dp"
android:layout_marginRight="#dimen/app_margin"
android:layout_marginBottom="#dimen/app_margin"/>
</LinearLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
<android.support.v7.widget.CardView
android:id="#+id/profile_pic"
android:layout_margin="#dimen/app_margin"
android:layout_width="100dp"
android:layout_height="100dp"
app:layout_anchor="#id/profile_card"
app:layout_anchorGravity="center|top"
app:cardCornerRadius="50dp"
app:cardBackgroundColor="#color/colorAccent">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="#drawable/ic_profile"/>
</android.support.v7.widget.CardView>
<android.support.design.widget.FloatingActionButton
android:id="#+id/buttonLove"
android:layout_width ="wrap_content"
android:layout_height="wrap_content"
android:src = "#drawable/ic_edit"
app:borderWidth="0dp"
android:elevation="5dp"
app:pressedTranslationZ="12dp"
app:rippleColor="#color/button_white"
android:onClick="onClick"
android:background="#color/colorAccent"
android:layout_margin="#dimen/app_margin"
android:layout_gravity="bottom|end"
app:fabSize="normal"
/>
</android.support.design.widget.CoordinatorLayout>
Related
I have a View in my activity where it contains one image, a text and a button...
So as you can see my button is showing there but its not visible...
It is going behind, I have tried to test it by marginTop attribute and if I move it down from the view then its visible...
I don't know how to do this but with the TextView when I use background then it changes the background color & works fine..
But I want to use Button instead of TextView
How can I do this or what I will have to do to bring the button front?
Below is my xml file code
<?xml version="1.0" encoding="utf-8"?>
<androidx.core.widget.NestedScrollView 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=".Dashboard">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<View
android:id="#+id/view"
android:layout_width="match_parent"
android:layout_height="250dp"
android:background="#drawable/dashboard_layout"
android:elevation="6dp"
android:transitionName="bg_anim"
android:layout_alignParentTop="true"
/>
<androidx.appcompat.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:elevation="6dp"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<!--This is the button-->
<!--Removed <Button
android:id="#+id/tv_welcome"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="32dp"
android:backgroundTint="#color/black"
android:elevation="6dp"
android:text="Hello,"
android:textColor="#fff"
android:textSize="35sp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/toolbar" />
-->
<--added newly-->
<Button
android:id="#+id/tv_welcome"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="32dp"
android:backgroundTint="#color/black"
android:elevation="6dp"
android:text="Hello,"
android:textColor="#fff"
android:textSize="35sp"
android:layout_alignParentStart="true"
android:layout_below="#+id/toolbar"/>
<TextView
android:id="#+id/tv_username"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:elevation="6dp"
android:text="Username"
android:textColor="#B2FFFFFF"
android:textSize="22sp"
android:transitionName="user_anim"
app:layout_constraintStart_toStartOf="#+id/tv_welcome"
app:layout_constraintTop_toTopOf="#+id/guideline3" />
<ImageView
android:id="#+id/iv_display_image"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_marginTop="10dp"
android:elevation="6dp"
android:padding="8dp"
android:transitionName="profile_anim"
android:layout_centerHorizontal="true"
app:layout_constraintDimensionRatio="h,1:1"
app:srcCompat="#drawable/ic_undraw_male_avatar" />
<TextView
android:id="#+id/tv_dashboard"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="48dp"
android:layout_marginTop="16dp"
android:text="Your Dashboard"
android:textColor="#ff1122"
android:textSize="20sp"
android:layout_below="#+id/view"/>
</RelativeLayout>
</androidx.core.widget.NestedScrollView>
After changing some code...
You are using RelativeLayout as parent and adding constraints to Button which only works when the parent is ConstraintLayout, to achieve same in RelativeLayout try android:layout_alignParentStart="true" and android:layout_below="#+id/toolbar" as in
<Button
android:id="#+id/tv_welcome"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="32dp"
android:backgroundTint="#color/black"
android:elevation="6dp"
android:text="Hello,"
android:textColor="#fff"
android:textSize="35sp"
android:layout_alignParentStart="true"
android:layout_below="#+id/toolbar" />
Also remove elevation on View as it is just setting background
<View
android:id="#+id/view"
android:layout_width="match_parent"
android:layout_height="250dp"
android:background="#drawable/dashboard_layout"
android:transitionName="bg_anim"
android:layout_alignParentTop="true"/>
<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">
<RelativeLayout
android:id="#+id/layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="#+id/header_cover_image"
android:layout_width="match_parent"
android:layout_height="200dp"
android:background="#drawable/my_gradient_background"
android:orientation="vertical"
android:scaleType="centerCrop"
/>
<ImageView
android:id="#+id/profile"
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_below="#+id/header_cover_image"
android:layout_centerHorizontal="true"
android:layout_marginTop="-150dp"
android:clickable="true"
android:elevation="5dp"
android:padding="20dp"
android:scaleType="centerCrop"
android:src="#drawable/app_icon"
app:civ_border_color="#FFFFFFFF"
app:civ_border_width="3dp" />
<RelativeLayout
android:id="#+id/profile_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/header_cover_image"
android:layout_marginLeft="10dp"
android:layout_marginTop="-50dp"
android:layout_marginRight="10dp"
android:background="#drawable/white_rounded_corner"
android:elevation="4dp"
android:paddingBottom="24dp">
<ImageView
android:id="#+id/save_profile"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:visibility="gone"
android:layout_marginRight="20dp"
android:clickable="true"
android:src="#android:drawable/ic_menu_save" />
<ImageView
android:id="#+id/edit_profile"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:layout_marginRight="20dp"
android:clickable="true"
android:src="#android:drawable/ic_menu_edit" />
<EditText
android:id="#+id/user_name_info"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="90dp"
android:background="#android:color/transparent"
android:inputType="none"
android:ems="50"
android:ellipsize="end"
android:focusable="false"
android:gravity="center"
android:maxLines="1"
android:text="Laxman Marothiya"
android:textColor="#000"
android:textSize="#dimen/normal_subTitle_font_size_eighteen"
android:textStyle="bold" />
<EditText
android:id="#+id/gender_info_textv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/user_name_info"
android:layout_centerHorizontal="true"
android:background="#android:color/transparent"
android:inputType="none"
android:focusable="false"
android:gravity="center"
android:ems="6"
android:maxLines="1"
android:text="Male"
android:textColor="#000"
android:textSize="#dimen/normal_subTitle_font_size_eighteen" />
<EditText
android:id="#+id/email_info_textv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/gender_info_textv"
android:layout_centerHorizontal="true"
android:background="#android:color/transparent"
android:inputType="none"
android:focusable="false"
android:gravity="center"
android:ems="40"
android:maxLines="1"
android:text="Emaol#gmail.com"
android:textColor="#000"
android:textSize="#dimen/normal_text_size_fifteen" />
<EditText
android:id="#+id/bio_info"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/email_info_textv"
android:layout_centerHorizontal="true"
android:layout_margin="5dp"
android:background="#android:color/transparent"
android:inputType="none"
android:focusable="false"
android:gravity="center"
android:padding="8dp"
android:ellipsize="end"
android:ems="200"
android:text="Here is my bio can you see it actually this is very interesting here "
android:textColor="#color/appBlackColor"
android:textSize="#dimen/normal_text_size_fifteen" />
</RelativeLayout>
</RelativeLayout>
I have a situation where linearlayout doesn't stay fixed at the bottom of the co-ordinatorlayout but moves with respect to the scrollview contents above.
I have tried all solutions on StackOverflow but still no luck (ex:Keep LinearLayout at the bottom of screen and even tried relativelayout but no luck: Make a RelativeLayout at the bottom of a Scrollview ). I am not sure what could be causing this, for the linear/relativelayout to move with respect to the scrollview, but if anyone else can figure out what I am doing wrong or missing, that'll be a great help!
Thanks in advance! Here's my XML code below: (open to sharing any other relevant java code if that helps )
<?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:background="#color/white"
android:clickable="false"
android:fitsSystemWindows="true"
android:fillViewport="true"
android:id="#+id/cl_root_view"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/main_register_container"
android:layout_marginBottom="60dp"
android:background="#color/white"
android:orientation="vertical">
<LinearLayout
android:id="#+id/activity_register_guest"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:elevation="0dp">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/white"
app:subtitleTextColor="#color/white"
app:titleTextAppearance="#style/Toolbar.TitleText"
app:titleTextColor="#color/white">
<!--<TextView
android:id="#+id/nav_back_btn"
style="#style/Body1RegLeftBlack"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="#dimen/activity_horizontal_margin"
android:layout_marginTop="20dp"
android:background="#drawable/ic_backarrow"
android:gravity="center_horizontal" />-->
<TextView
android:id="#+id/register_guest_main_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="18dp"
android:layout_marginTop="15dp"
android:layout_gravity="center"
android:letterSpacing="0.01"
android:textAllCaps="true"
android:text="#string/register_guest"
android:textAppearance="#style/TextAppearance.Text.Roboto.Medium"
android:textColor="#de000000"
android:textSize="17sp"
android:textStyle="normal"
/>
</android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
android:background="#color/white"
android:fitsSystemWindows="true"
android:layout_marginBottom="65dp">
<RelativeLayout
android:id="#+id/register_visitor_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/white"
android:clickable="false"
android:fillViewport="true">
<LinearLayout
android:id="#+id/main_register_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp">
<TextView
android:id="#+id/my_location"
style="#style/Headline2LeftBlack"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="#dimen/activity_horizontal_margin"
android:textAppearance="#style/TextAppearance.Text.Chronicle"
android:textSize="28sp"
tools:text="#string/five_thirty_fifth_ave" />
<TextView
style="#style/Body1RegRightRed"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/my_location"
android:layout_alignParentEnd="true"
android:layout_marginEnd="#dimen/activity_horizontal_margin"
android:layout_toEndOf="#+id/my_location"
android:text="#string/location_change"
android:textAppearance="#style/TextAppearance.Text.Roboto.Regular"
android:visibility="gone" />
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="28dp"
android:layout_marginTop="24dp"
android:gravity="center_vertical"
android:layout_marginBottom="8dp"
android:weightSum="2">
<TextView
android:id="#+id/select_date_and_time"
android:layout_width="wrap_content"
android:textSize="17sp"
android:lineSpacingExtra="6sp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:textColor="#color/black"
android:text="#string/select_date_and_time"
android:textAppearance="#style/TextAppearance.Text.Roboto.Medium" />
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:background="#color/registerUserSeparatorColor" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="48dp"
android:gravity="center_vertical"
android:weightSum="2">
<TextView
android:id="#+id/register_guest_start_date"
style="#style/Body1RegLeftBlack"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_weight="1"
android:text="#string/register_guest_start_date"
android:textAppearance="#style/TextAppearance.Text.Roboto.Regular" />
<TextView
android:id="#+id/register_guest_start_time"
style="#style/Body1RegRightBlack"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:layout_weight="1"
android:text="#string/register_guest_start_time"
android:textAppearance="#style/TextAppearance.Text.Roboto.Regular" />
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:background="#color/registerUserSeparatorColor" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="48dp"
android:gravity="center_vertical"
android:weightSum="2">
<TextView
android:id="#+id/register_guest_end_date"
style="#style/Body1RegLeftBlack"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_weight="1"
android:text="#string/register_guest_end_date"
android:textAppearance="#style/TextAppearance.Text.Roboto.Regular"
android:visibility="invisible" />
<TextView
android:id="#+id/register_guest_end_time"
style="#style/Body1RegRightBlack"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:layout_weight="1"
android:text="#string/register_guest_end_time"
android:textAppearance="#style/TextAppearance.Text.Roboto.Regular" />
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:background="#color/registerUserSeparatorColor" />
<TextView
android:id="#+id/build_your_guest_list"
android:layout_width="wrap_content"
android:textSize="17sp"
android:layout_marginTop="42dp"
android:lineSpacingExtra="6sp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:textColor="#color/black"
android:text="#string/build_your_guest_list"
android:paddingBottom="8dp"
android:textAppearance="#style/TextAppearance.Text.Roboto.Medium" />
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:background="#color/registerUserSeparatorColor" />
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="44dp"
android:id="#+id/add_guest"
android:layout_marginTop="3dp"
android:layout_marginBottom="8dp"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="44dp"
android:lineHeight="22sp"
android:drawablePadding="10dp"
android:drawableStart="#drawable/ic_add_24px"
android:drawableTint="#color/bluish"
android:layout_marginStart="17dp"
android:lineSpacingExtra="6sp"
android:textColor="#color/bluish"
android:gravity="center_vertical"
android:textAppearance="#style/TextAppearance.Text.Roboto.Medium"
android:text="#string/add_a_new_guest"
android:textSize="17sp" />
</RelativeLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:background="#color/registerUserSeparatorColor"
/>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="44dp"
android:id="#+id/search_guest"
android:layout_marginTop="3dp"
android:visibility="gone"
android:layout_marginBottom="8dp"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="44dp"
android:lineHeight="22sp"
android:drawablePadding="10dp"
android:drawableStart="#drawable/ic_search_24px"
android:drawableTint="#color/bluish"
android:layout_marginStart="17dp"
android:lineSpacingExtra="6sp"
android:textColor="#color/bluish"
android:gravity="center_vertical"
android:textAppearance="#style/TextAppearance.Text.Roboto.Medium"
android:text="#string/search_past_guests"
android:textSize="17sp" />
</RelativeLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:visibility="gone"
android:id="#+id/search_guest_line"
android:background="#color/registerUserSeparatorColor"
/>
<android.support.v7.widget.RecyclerView
android:id="#+id/guest_item_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:divider="#null"
android:overScrollMode="never"
tools:listitem="#layout/item_guest" />
<TextView
android:id="#+id/arrival_notifications"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="58dp"
android:letterSpacing="0.01"
android:lineSpacingExtra="4sp"
android:text="#string/arrival_notifications"
android:textAppearance="#style/TextAppearance.Text.Roboto.Medium"
android:textColor="#color/black"
android:textSize="20sp"
android:textStyle="normal"
android:visibility="invisible" />
<RelativeLayout
android:id="#+id/text_message_container"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:visibility="gone">
<TextView
android:id="#+id/text_message"
style="#style/Body1RegLeftBlack"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="11dp"
android:text="#string/text_message"
android:textAppearance="#style/TextAppearance.Text.Roboto.Regular" />
<TextView
android:id="#+id/tap_phone_number_text"
style="#style/Body2RegLeftGrey"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/text_message"
android:layout_marginTop="2dp"
android:text="#string/tap_to_add_a_phone_number"
android:textAppearance="#style/TextAppearance.Text.Roboto.Regular" />
<android.support.v7.widget.SwitchCompat
android:id="#+id/text_message_switch"
style="#style/Color1SwitchStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
android:layout_marginEnd="16dp" />
</RelativeLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginStart="16dp"
android:layout_marginTop="11dp"
android:background="#color/settingsSeparatorLineColor"
android:visibility="gone" />
</LinearLayout>
<!-- <TextView
android:id="#+id/submit_users_btn"
style="#style/LoginButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center|bottom"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:paddingBottom="30dp"
android:letterSpacing="0.07"
android:lineSpacingExtra="0sp"
android:text="#string/submit_visitor_list"
android:textAppearance="#style/TextAppearance.Text.Roboto.Medium"
android:textSize="16sp"
android:textStyle="normal" /> -->
</RelativeLayout>
</ScrollView>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentStart="true"
android:layout_alignParentEnd="true"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:layout_gravity="center|bottom"
android:background="#color/transparent"
android:layout_marginBottom="75dp"
android:orientation="vertical"
android:id="#+id/fixedSubmitButtonlayout">
<TextView
android:id="#+id/submit_users_btn"
android:textColor="#757575"
android:textAlignment="center"
android:layout_width="match_parent"
android:layout_height="40dp"
android:background="#drawable/textview_border"
android:letterSpacing="0.07"
android:gravity="center"
android:lineSpacingExtra="0sp"
android:text="#string/register_guest_caps"
android:textAppearance="#style/TextAppearance.Text.RidleyGrotesk.Regular"
android:textSize="16sp"
android:textStyle="normal" />
</LinearLayout>
</android.support.design.widget.CoordinatorLayout>
From the code above, the layout I am trying to fix at the bottom has id is: android:id="#+id/fixedSubmitButtonlayout".
I want it to stay intact/fixed at the bottom of the screen irrespective of the scrollview above it which is supposed to scroll behind it ( it does as of now, just the button position changes as the scroll view content overflows screen size). any ideas on how to fix this?
Just need to do this steps:
add a RelativeLayout as a Parent of CoordinatorLayout and
take out the last LinearLayout from CoordinatorLayout and
add it to RelativeLayout with android:layout_alignParentBottom="true".
note that you need to add android:layout_marginBottom="40dp" to your CoordinatorLayout
You can try this (tested and it works fine):
<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"
>
<your CoordinatorLayout>
</your CoordinatorLayout>
<LinearLayout
android:id="#+id/fixedSubmitButtonlayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_gravity="center|bottom"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:background="#color/transparent"
android:orientation="vertical"
>
<TextView
android:id="#+id/submit_users_btn"
android:layout_width="match_parent"
android:layout_height="40dp"
android:background="#drawable/textview_border"
android:gravity="center"
android:letterSpacing="0.07"
android:lineSpacingExtra="0sp"
android:text="#string/register_guest_caps"
android:textAlignment="center"
android:textAppearance="#style/TextAppearance.Text.RidleyGrotesk.Regular"
android:textColor="#757575"
android:textSize="16sp"
android:textStyle="normal"
/>
</LinearLayout>
</RelativeLayout>
It will work better in Relative layout
android:layout_alignParentBottom="true"
In your CoordinatorLayout, your View must be a direct child and not a child of another View inside the CoordinatorLayout. Then you can add this line of code to it:
android:layout_gravity="bottom"
The structure can be like this:
- CoordinatorLayout //(Parent View)
- - AppBarLayout //(Child View - Toolbar)
- - NestedScrollView //(Child View - Scrollable Content)
- - LinearLayout //(Child View - Bottom Fixed Content)
Here's a Sample code how it's supposed to be:
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<com.google.android.material.appbar.AppBarLayout
android:id="#+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/black_overlay"
android:theme="#style/AppTheme.AppBarOverlay">
<androidx.appcompat.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:theme="#style/Toolbar.Light"
app:contentInsetStartWithNavigation="0dp"
app:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light">
</androidx.appcompat.widget.Toolbar>
</com.google.android.material.appbar.AppBarLayout>
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<!--Your Scrollable Content Goes Here-->
</LinearLayout>
</androidx.core.widget.NestedScrollView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:orientation="vertical">
<!--Your Fixed Bottom Content Goes Here-->
</LinearLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
I have a bottomNavigationView in the MainActivity. When I click to second (SearchFragment) and last (AccountFragment) item,the height of bottomNavigationView become small and when again click on same menu item, the height of bottomNavigationView become normal.This happens only when I'm in home item(HomeFragment) and from there I navigate to second or last item.There isn't this problem in the third menu item (MyCourseFragment).
It is screenshot of normal state:
This is layout of MainActivity:
<android.support.design.widget.CoordinatorLayout
android:id="#+id/coordinatorLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<FrameLayout
android:id="#+id/flContent"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="56dp"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
<ProgressBar
android:id="#+id/progressBar"
style="?android:attr/progressBarStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:visibility="visible"/>
</FrameLayout>
<android.support.design.widget.BottomNavigationView
android:id="#+id/bottom_nav"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
app:menu="#menu/bottom_nav_menu"
app:itemBackground="#color/colorBackgroundNav"
android:theme="#style/bottomNav"
app:labelVisibilityMode="labeled"
android:layout_gravity="bottom"
/>
</android.support.design.widget.CoordinatorLayout>
It is layout of MyCourseFragment:
<RelativeLayout xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context=".view.MyCourseFragment">
<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"
android:background="#color/colorPrimary">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="دوره های من"
android:layout_gravity="end"
android:id="#+id/toolbar_title"
android:layout_marginEnd="20dp"
android:textColor="#fff"
android:textStyle="bold"
android:textSize="17sp"/>
</android.support.v7.widget.Toolbar>
<android.support.v7.widget.RecyclerView
android:id="#+id/courseRcy"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/toolbar"
android:layout_marginTop="30dp"
android:visibility="gone"/>
<android.support.v7.widget.RecyclerView
android:id="#+id/categoryRcy"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/toolbar"
android:layout_marginTop="30dp"/>
</RelativeLayout>
It is layout of `SearchFragment`:
<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=".view.SearchFragment">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="#color/colorPrimary"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light"/>
<SearchView
android:id="#+id/searchbox"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_centerInParent="true"
android:layout_margin="10dp"
android:background="#FFF"></SearchView>
<android.support.v7.widget.RecyclerView
android:id="#+id/CategoryRcy"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/searchbox"
android:layout_marginTop="10dp" />
</RelativeLayout>
It is layout 'AccountFragment':
<ScrollView android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context=".view.AccountFragment">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:fitsSystemWindows="true"
android:minHeight="?attr/actionBarSize"
app:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="حساب کاربری"
android:layout_gravity="end"
android:id="#+id/toolbar_title"
android:layout_marginEnd="20dp"
android:textColor="#fff"
android:textStyle="bold"
android:textSize="17sp"/>
</android.support.v7.widget.Toolbar>
<android.support.v7.widget.CardView
android:id="#+id/cardViewProfile"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_marginStart="10dp"
android:layout_marginEnd="10dp"
app:cardCornerRadius="15dp"
android:layout_below="#+id/toolbar"
android:visibility="gone">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="#+id/imgAvatar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_avatar"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"/>
<TextView
android:id="#+id/txtName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="مریم کاظمی"
android:layout_below="#id/imgAvatar"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp"
/>
</RelativeLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:id="#+id/cardViewInstructor"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/cardViewProfile"
android:layout_marginTop="20dp"
android:layout_marginStart="10dp"
android:layout_marginEnd="10dp"
app:cardCornerRadius="15dp"
android:padding="10dp"
android:visibility="gone">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/txtBeInstructor"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="یک مدرس شو"
android:layout_centerInParent="true"
android:textColor="#color/colorPrimary"
android:textStyle="bold"
android:textSize="20sp"
/>
</RelativeLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:id="#+id/cardViewSetting"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/cardViewInstructor"
android:layout_marginTop="20dp"
android:layout_marginStart="10dp"
android:layout_marginEnd="10dp"
app:cardCornerRadius="15dp"
android:visibility="gone">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/txtPreferences"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_marginTop="20dp"
android:layout_marginEnd="10dp"
android:text="تنظیمات"/>
<TextView
android:id="#+id/txtLecturePlayBack"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_marginTop="20dp"
android:layout_marginEnd="10dp"
android:text="پخش دوره"
android:layout_below="#+id/txtPreferences"/>
<TextView
android:id="#+id/txtContinueBackground"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_marginTop="10dp"
android:layout_marginEnd="10dp"
android:text="پخش پیوسته در بک گراند"
android:layout_below="#+id/txtLecturePlayBack"/>
<Switch
android:id="#+id/switchCB"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_below="#+id/txtLecturePlayBack"
android:layout_marginTop="10dp"
android:layout_marginStart="20dp"/>
<TextView
android:id="#+id/txtDownloadOption"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_marginTop="20dp"
android:layout_marginEnd="10dp"
android:text="گزینه های دانلود ویدیو"
android:layout_below="#+id/txtContinueBackground"/>
<TextView
android:id="#+id/txtDWiFi"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_marginTop="10dp"
android:layout_marginEnd="10dp"
android:text="دانلود فقط از طریق Wi-Fi"
android:layout_below="#+id/txtDownloadOption"/>
<Switch
android:id="#+id/switchDWifi"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_below="#+id/txtDownloadOption"
android:layout_marginTop="10dp"
android:layout_marginStart="20dp"/>
<TextView
android:id="#+id/txtDSD"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_marginTop="20dp"
android:layout_marginEnd="10dp"
android:text="دانلود داخل کارت حافظه"
android:layout_below="#+id/txtDWiFi"/>
<Switch
android:id="#+id/switchDSD"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_below="#+id/txtDWiFi"
android:layout_marginTop="20dp"
android:layout_marginStart="20dp"/>
<TextView
android:id="#+id/txtQualityVideo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_marginTop="20dp"
android:layout_marginEnd="10dp"
android:text="کیفیت دانلود ویدیو"
android:layout_below="#+id/txtDSD"/>
<TextView
android:id="#+id/txtQuality"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/txtQualityVideo"
android:layout_alignParentEnd="true"
android:text="360p"
android:layout_marginTop="5dp"
android:layout_marginEnd="10dp"/>
<TextView
android:id="#+id/txtTitleEditNotf"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_marginTop="20dp"
android:layout_marginEnd="10dp"
android:text="تنظیمات نوتیفیکیشن"
android:layout_below="#+id/txtQuality"/>
<TextView
android:id="#+id/txtEditNotf"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/txtTitleEditNotf"
android:layout_alignParentEnd="true"
android:text="ویرایش تنظیمات نوتیفیکیشن ها"
android:layout_marginTop="10dp"
android:layout_marginEnd="10dp"
android:layout_marginBottom="20dp"/>
</RelativeLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:id="#+id/cardViewPolicy"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_marginStart="10dp"
android:layout_marginEnd="10dp"
app:cardCornerRadius="15dp"
android:layout_below="#+id/cardViewSetting"
android:visibility="visible"
android:layout_marginBottom="10dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/txtShareApp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="پارس کلاس را به اشتراک بگذار"
android:layout_alignParentEnd="true"
android:layout_marginTop="20dp"
android:layout_marginEnd="10dp"
/>
<TextView
android:id="#+id/txtPrivacy"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="مشاهده سیاست های حریم خصوصی"
android:layout_below="#+id/txtShareApp"
android:layout_alignParentEnd="true"
android:layout_marginTop="20dp"
android:layout_marginEnd="10dp"
/>
<TextView
android:id="#+id/txtTermOfUse"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="مقررات استفاده"
android:layout_below="#+id/txtPrivacy"
android:layout_alignParentEnd="true"
android:layout_marginTop="20dp"
android:layout_marginEnd="10dp"
/>
<TextView
android:id="#+id/txtIntellectual"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="مشاهده سیاست مالکیت معنوی"
android:layout_below="#+id/txtTermOfUse"
android:layout_alignParentEnd="true"
android:layout_marginTop="20dp"
android:layout_marginEnd="10dp"
/>
<TextView
android:id="#+id/txtSign"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ورود/ثبت نام"
android:layout_below="#+id/txtIntellectual"
android:layout_centerInParent="true"
android:layout_marginTop="10dp"/>
<TextView
android:id="#+id/txtVersion"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ParsClass v1.1"
android:layout_below="#+id/txtSign"
android:layout_centerInParent="true"
android:layout_marginTop="10dp"
android:paddingBottom="10dp"/>
</RelativeLayout>
</android.support.v7.widget.CardView>
</RelativeLayout>
</ScrollView>
Finally i find the solution.I just needed to add this line of code to onCreateView method of Account fragment.
((AppCompatActivity)getActivity()).setSupportActionBar(toolbar);
I don't understand why my CollapsingToolbar layout is collapsed when my view is created by default.
I think this the NestedScrollView the responsible but i don't no why.
This make me crazy.
My activity layout :
<android.support.design.widget.AppBarLayout
android:id="#+id/app_bar"
android:layout_width="match_parent"
android:layout_height="#dimen/app_bar_height"
android:fitsSystemWindows="true"
android:theme="#style/AppTheme.AppBarOverlay">
<android.support.design.widget.CollapsingToolbarLayout
android:id="#+id/toolbar_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:contentScrim="?attr/colorPrimary"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<android.support.v4.view.ViewPager
android:id="#+id/pager_images"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:scaleType="centerCrop"
app:layout_collapseMode="parallax"/>
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin"
app:popupTheme="#style/AppTheme.PopupOverlay" />
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<include layout="#layout/content_product" />
</android.support.design.widget.CoordinatorLayout>
And my content_layout with nested scrollview :
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="4dp">
<include layout="#layout/layout_progress" />
<TextView
android:id="#+id/tv_reference"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="2dp"
android:layout_marginTop="8dp"
android:ellipsize="end"
android:maxLines="1"
android:text=""
android:textColor="#color/MyApp_gray"
android:textSize="10sp"
android:textStyle="bold" />
<TextView
android:id="#+id/tv_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="8dp"
android:layout_marginTop="8dp"
android:ellipsize="end"
android:fontFamily="sans-serif-light"
android:maxLines="2"
android:text=""
android:textColor="#color/cardview_dark_background"
android:textSize="16sp" />
<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:id="#+id/card_view_choix"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="4dp"
android:layout_marginLeft="4dp"
android:layout_marginRight="4dp"
android:layout_marginTop="4dp"
android:background="#android:color/white"
card_view:cardCornerRadius="2dp"
card_view:cardElevation="1dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical"
android:paddingLeft="10dp"
android:paddingRight="10dp">
<TextView
android:id="#+id/tv_quantity_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="8dp"
android:ellipsize="end"
android:maxLines="2"
android:text="#string/product_quantity"
android:textColor="#color/cardview_dark_background"
android:textSize="12sp" />
<com.MyApp.utils.HorizontalNumberPicker
android:id="#+id/horizontal_qty_picker"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<View
android:layout_width="match_parent"
android:layout_height="1px"
android:layout_marginLeft="0dp"
android:layout_marginRight="0dp"
android:background="#color/MyApp_gray" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:gravity="center"
android:orientation="horizontal">
<TextView
android:id="#+id/tv_price"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text=""
android:textColor="#color/cardview_dark_background"
android:textSize="18sp"
android:textStyle="" />
<TextView
android:id="#+id/tv_price_unit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text=" / Unité"
android:textColor="#color/cardview_dark_background"
android:textSize="16sp" />
</LinearLayout>
<TextView
android:id="#+id/tv_duration"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="10dp"
android:drawableLeft="#drawable/ic_hourglass_red_18dp"
android:drawablePadding="4dp"
android:gravity="center"
android:maxLines="2"
android:text=""
android:textColor="#color/MyApp_gray"
android:textSize="12sp"
android:visibility="gone" />
</LinearLayout>
</android.support.v7.widget.CardView>
<Button
android:id="#+id/btn_book"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="30dp"
android:layout_marginTop="10dp"
android:background="#drawable/btn_primary"
android:drawableLeft="#drawable/ic_add_shopping_cart_white_24dp"
android:drawablePadding="10dp"
android:paddingLeft="20dp"
android:paddingRight="20dp"
android:text="#string/store_action_book"
android:textColor="#android:color/white"
android:textStyle="bold" />
<TextView
android:id="#+id/tv_desc_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="2dp"
android:layout_marginTop="20dp"
android:ellipsize="end"
android:maxLines="1"
android:text="#string/product_description"
android:textColor="#color/cardview_dark_background"
android:textSize="14sp"
android:textStyle="bold" />
<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:id="#+id/card_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="4dp"
android:layout_marginLeft="4dp"
android:layout_marginRight="4dp"
android:layout_marginTop="4dp"
android:background="#android:color/white"
card_view:cardCornerRadius="2dp"
card_view:cardElevation="1dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingLeft="10dp"
android:paddingRight="10dp">
<at.blogc.android.views.ExpandableTextView
android:id="#+id/tv_description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="0dp"
android:layout_marginTop="10dp"
android:ellipsize="end"
android:maxLines="5"
android:text=""
android:textColor="#color/MyApp_gray"
android:textIsSelectable="true"
android:textSize="12sp"
app:animation_duration="1000" />
<Button
android:id="#+id/btn_more"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:background="#android:color/transparent"
android:text="#string/action_expand"
android:textColor="#color/MyApp_red" />
</LinearLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
Rendering :
More strange it still working when i use the NestedScrollView to top. It seems like the NestedScrollView scroll to bottom automatically.
Solved with this thread :
nestedscrollview-scroll-down-itself-when-content-is-fills
android:descendantFocusability="blocksDescendants" to the LinearLayout inside NestedScrollView
Worked for me.
I'm trying to create a layout like below.
The problem is that the FAB is changing position in some devices because i have hardcoded the bottom margin.
I want the FAB as like in the below image.
PRESENT 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:background="#drawable/mlogin">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.CardView
android:id="#+id/card"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_margin="30dp"
android:elevation="8dp"
app:cardCornerRadius="10dp">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_margin="30dp"
android:orientation="vertical">
<ImageView
android:id="#+id/logo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:padding="10dp"
android:src="#drawable/selfiel" />
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="center"
android:text="Login"
android:textAlignment="center"
android:textColor="#color/colorAccent"
android:textSize="22sp" />
<!-- Email Label -->
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="#+id/input_email"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Email"
android:inputType="textEmailAddress"
android:textColor="#color/white" />
</android.support.design.widget.TextInputLayout>
<!-- Password Label -->
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="40dp">
<EditText
android:id="#+id/input_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Password"
android:inputType="textPassword"
android:textColor="#color/white" />
</android.support.design.widget.TextInputLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
<android.support.design.widget.FloatingActionButton
android:id="#+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/forgot"
android:layout_centerHorizontal="true"
android:layout_marginBottom="103dp"
android:src="#drawable/ic_done" />
<TextView
android:id="#+id/forgot"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/submit"
android:layout_centerHorizontal="true"
android:layout_gravity="center"
android:text="Forgot password?"
android:textColor="#color/white"
android:textSize="18sp" />
<android.support.v7.widget.AppCompatButton
android:id="#+id/submit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_margin="20dp"
android:background="#color/colorAccent"
android:onClick="submit"
android:text="Sign Up"
android:textColor="#color/white"
android:textSize="18sp" />
</RelativeLayout>
</RelativeLayout>
You probably want to use the CoordinatorLayout.
The basic layout would be as follows:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android: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:background="#drawable/mlogin">
<android.support.v7.widget.CardView
android:id="#+id/card"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_margin="30dp"
android:elevation="8dp"
app:cardCornerRadius="10dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="30dp"
android:orientation="vertical">
<ImageView
android:id="#+id/logo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:padding="10dp"
android:src="#drawable/selfiel" />
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="center"
android:text="Login"
android:textAlignment="center"
android:textColor="#color/colorAccent"
android:textSize="22sp" />
<!-- Email Label -->
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="#+id/input_email"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Email"
android:inputType="textEmailAddress"
android:textColor="#color/white" />
</android.support.design.widget.TextInputLayout>
<!-- Password Label -->
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="40dp">
<EditText
android:id="#+id/input_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Password"
android:inputType="textPassword"
android:textColor="#color/white" />
</android.support.design.widget.TextInputLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="bottom">
<TextView
android:id="#+id/forgot"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="Forgot password?"
android:textColor="#color/white"
android:textSize="18sp" />
<android.support.v7.widget.AppCompatButton
android:id="#+id/submit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:text="Sign Up"
android:onClick="submit"
android:background="#color/colorAccent"
android:textColor="#color/white"
android:textSize="18sp"
android:layout_gravity="bottom|center_horizontal" />
</LinearLayout>
</android.support.design.widget.AppBarLayout>
<android.support.design.widget.FloatingActionButton
android:id="#+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_done"
app:layout_anchor="#id/card"
app:layout_anchorGravity="bottom|center"/>
</android.support.design.widget.CoordinatorLayout>
The magic lines here are in the FloatingActionButton that say:
app:layout_anchor="#id/card"
app:layout_anchorGravity="bottom|center"
This essentially tells your layout that the FAB is related to the card, and that it should be positioned relative to the card (centered at the bottom).
You can find the CoordinatorLayout documentation here, and a pretty good tutorial here.
Best of luck!
use android:layout_gravity="bottom" instead Then adjust with margins if you want. so you can do this:
<android.support.design.widget.FloatingActionButton
android:id="#+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/forgot"
android:layout_centerHorizontal="true"
android:layout_marginBottom="13dp"
android:layout_gravity="bottom"
android:src="#drawable/ic_done" />