I have this problem to accommodate my floating button, and I do not understand why it does not work.
I would appreciate your response since I can not find the reason why this is happening, one more detail when scrolling or reloading the fragment some of the floating buttons will be accommodated.
And sorry for my English.
<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="wrap_content"
android:background="#color/colorBackground"
android:orientation="vertical">
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
<android.support.v7.widget.CardView
android:id="#+id/mRequestCard"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:elevation="100dp"
android:orientation="horizontal"
app:cardBackgroundColor="#color/colorWhite"
app:cardCornerRadius="3dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<View
android:id="#+id/vDivisor"
android:layout_width="match_parent"
android:layout_height="2dp"
android:background="#color/colorGreen" />
...
</RelativeLayout>
</android.support.v7.widget.CardView>
</android.support.v4.widget.NestedScrollView>
<android.support.design.widget.FloatingActionButton
android:id="#+id/fab"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_marginRight="#dimen/fab_margin"
android:backgroundTint="#color/colorPurple"
android:scaleType="centerCrop"
android:src="#drawable/ic_route_direction"
app:layout_anchor="#id/mRequestCard"
app:layout_anchorGravity="right|end|bottom" />
</android.support.design.widget.CoordinatorLayout>
And this is my RecyclerView Which is inflated in a fragment
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.test.HistorialFragment">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="#+id/mRecyclerRequest"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
</FrameLayout>
And this is my fragment, where I show the RecyclerView
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context="com.test.MainActivity"
tools:showIn="#layout/app_bar_main">
</FrameLayout>
you should try RelativeLayout like this
<RelativeLayout android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="horizontal"
xmlns:android="http://schemas.android.com/apk/res/android">
<android.support.design.widget.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:backgroundTint="#color/colorBlack"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"/>
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:cardCornerRadius="#dimen/activity_corner"
android:layout_marginBottom="#dimen/activity_margin">
<!--your cardview item here-->
</android.support.v7.widget.CardView>
</RelativeLayout>
for your RecyclerView item
Check if this helps you:
<?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"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/colorPrimary"
android:orientation="vertical">
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
<android.support.v7.widget.CardView
android:id="#+id/mRequestCard"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:elevation="100dp"
android:orientation="horizontal"
app:cardBackgroundColor="#color/colorWhite"
app:cardCornerRadius="3dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<View
android:id="#+id/vDivisor"
android:layout_width="match_parent"
android:layout_height="2dp"
android:background="#color/colorGreen" />
...
</RelativeLayout>
</android.support.v7.widget.CardView>
</android.support.v4.widget.NestedScrollView>
<android.support.design.widget.FloatingActionButton
android:id="#+id/fab"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_alignParentRight="true"
android:layout_marginRight="10dp"
android:backgroundTint="#color/colorAccent"
android:scaleType="centerCrop"
android:src="#drawable/ic_launcher"
app:layout_anchor="#id/mRequestCard"
app:layout_anchorGravity="right|end|bottom" />
</RelativeLayout>
try this use RelativeLayout and make your FloatingActionButton property android:layout_alignParentBottom="true" and
android:layout_alignParentRight="true" like below code
<RelativeLayout android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="horizontal"
xmlns:android="http://schemas.android.com/apk/res/android">
<android.support.design.widget.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:backgroundTint="#color/colorBlack"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"/>
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:cardCornerRadius="#dimen/activity_corner"
android:layout_marginBottom="#dimen/activity_margin">
</android.support.v7.widget.CardView>
</RelativeLayout>
Related
I am getting java.lang.RuntimeException: Unable to start activity java.lang.IllegalArgumentException: The view is not a child of CoordinatorLayout.working with bottom sheet, I have tried lot of combination but still i am not getting solution. please tell me any solution.Thank you in advance.
<?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"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/beyprod"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:id="#+id/toolbarLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:orientation="vertical">
<include
android:id="#+id/toolbar"
layout="#layout/toolbar" />
</LinearLayout>
<!-- <LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<FrameLayout
android:id="#+id/bottom_sheet"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_behavior="#string/bottom_sheet_behavior" />
</LinearLayout>-->
<android.support.v4.widget.NestedScrollView
android:id="#+id/bottom_sheet"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
app:layout_behavior="#string/bottom_sheet_behavior">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".retailerModule.cart.activity.AddressListActivity">
<ProgressBar
android:id="#+id/progress_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/relaLaySearch"
android:layout_gravity="center|top"
android:visibility="gone" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/confirmBtn"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.RecyclerView
android:id="#+id/recycler"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</android.support.v7.widget.RecyclerView>
</LinearLayout>
<TextView
android:id="#+id/addNewAddress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_gravity="right"
android:layout_marginTop="15dp"
android:layout_marginRight="10dp"
android:layout_marginBottom="40dp"
android:background="#color/green"
android:gravity="center"
android:padding="10dp"
android:text="New Address"
android:textColor="#color/colorWhite" />
</LinearLayout>
<android.support.v7.widget.AppCompatButton
android:id="#+id/continueBtn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_gravity="right"
android:background="#color/color_blue"
android:gravity="center"
android:text="SAVE"
android:textColor="#color/colorWhite"
android:visibility="gone" />
</RelativeLayout>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
</LinearLayout>
When i tried to run this line getting exception
NestedScrollView mBehavior = BottomSheetBehavior.from(bottom_sheet);
It tells you that you can only put a BottomSheetBehavior into a CoordinatorLayout.
So make CoordinatorLayout as your root layout and place it directly here (not in some nested views)
I have an activity that includes a fragment, inside it I have a map using google maps api, and I want to add a bottom sheet which should automatically move up my location floating button until it reach a medium height.
Here is my fragment:
<?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.v4.widget.DrawerLayout
android:layout_height="match_parent"
android:layout_width="match_parent">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.android.gms.maps.MapView
android:id="#+id/mapView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<android.support.design.widget.FloatingActionButton
android:id="#+id/my_location_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_marginBottom="66dp"
app:backgroundTint="#ffffff"
app:elevation="6dp"
app:layout_anchor="#id/mapView"
app:layout_anchorGravity="bottom|right|end"
app:pressedTranslationZ="12dp"
app:srcCompat="#drawable/ic_my_location_black_24dp" />
</android.support.design.widget.CoordinatorLayout>
</FrameLayout>
</android.support.v4.widget.DrawerLayout>
<android.support.v4.widget.NestedScrollView
android:id="#+id/bottom_sheet"
android:layout_width="match_parent"
android:layout_height="350dp"
android:background="#android:color/holo_blue_light"
app:behavior_hideable="false"
app:behavior_peekHeight="55dp"
android:clipToPadding="true"
app:layout_behavior="#string/bottom_sheet_behavior">
<FrameLayout
android:id="#+id/job_frame"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginBottom="2dp" />
</android.support.v4.widget.NestedScrollView>
I want to archive something like that, look at the my location button:
https://www.youtube.com/watch?v=iwpR_uzqTq4
Try anchor your fab with your sheet and put the anchor gravity as top|right as follow
<?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.v4.widget.DrawerLayout
android:layout_height="match_parent"
android:layout_width="match_parent">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.android.gms.maps.MapView
android:id="#+id/mapView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</android.support.design.widget.CoordinatorLayout>
</FrameLayout>
</android.support.v4.widget.DrawerLayout>
<android.support.v4.widget.NestedScrollView
android:id="#+id/bottom_sheet"
android:layout_width="match_parent"
android:layout_height="350dp"
android:background="#android:color/holo_blue_light"
app:behavior_hideable="false"
app:behavior_peekHeight="55dp"
android:clipToPadding="true"
app:layout_behavior="#string/bottom_sheet_behavior">
<FrameLayout
android:id="#+id/job_frame"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginBottom="2dp" />
</android.support.v4.widget.NestedScrollView>
<android.support.design.widget.FloatingActionButton
android:id="#+id/my_location_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_marginBottom="66dp"
app:backgroundTint="#ffffff"
app:elevation="6dp"
app:layout_anchor="#id/bottom_sheet"
app:layout_anchorGravity="top|end"
app:pressedTranslationZ="12dp"
app:srcCompat="#drawable/ic_my_location_black_24dp" />
</android.support.design.widget.CoordinatorLayout>
In my application I want use NestedScrollView into DrawerLayout.
And for this I write below code.
I want show FAB in bottom of layout, but show me below of card!
I don't want show in below of card, I want show bottom of layout!
Please see below image to understand what I mean:
My codes:
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res-auto"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/toNightDrawerLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="end">
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:id="#+id/reviewSerialFrag_newsCommentsLay"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="visible">
<android.support.v7.widget.CardView
android:id="#+id/reviewSerialFrag_newsCommentsCard"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="#dimen/padding8"
ads:cardBackgroundColor="#android:color/white"
ads:cardElevation="#dimen/size2"
app:contentPadding="#dimen/padding8">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:id="#+id/reviewSerialFrag_newsCommentsHeaderLay"
android:layout_width="match_parent"
android:layout_height="#dimen/size50">
<ImageView
android:id="#+id/reviewSerialFrag_newsCommentsHeaderImage"
android:layout_width="#dimen/size35"
android:layout_height="#dimen/size35"
android:layout_centerVertical="true"
android:alpha="0.8"
android:src="#drawable/ic_comments"
android:tint="#color/darkBlueGrey" />
<TextView
android:id="#+id/reviewSerialFrag_newsCommentsUserTypeText"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_margin="#dimen/padding10"
android:layout_toRightOf="#+id/reviewSerialFrag_newsCommentsHeaderImage"
android:fontFamily="sans-serif-light"
android:gravity="center_vertical"
android:textColor="#color/darkBlueGrey"
android:textSize="#dimen/font16" />
<TextView
android:id="#+id/reviewSerialFrag_newsCommentsReviewTypeText"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_margin="#dimen/padding10"
android:layout_toRightOf="#+id/reviewSerialFrag_newsCommentsUserTypeText"
android:fontFamily="sans-serif-light"
android:gravity="center_vertical"
android:textColor="#color/darkBlueGrey"
android:textSize="#dimen/font14" />
</RelativeLayout>
<android.support.v7.widget.RecyclerView
android:id="#+id/reviewSerialFrag_newsCommentsRecyclerView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/reviewSerialFrag_newsCommentsHeaderLay"
android:layout_marginTop="#dimen/padding5" />
</RelativeLayout>
</android.support.v7.widget.CardView>
</RelativeLayout>
<!--EmptyList-->
<RelativeLayout
android:id="#+id/reviewSerialFrag_EmptyLsy"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone">
<include layout="#layout/empty_list" />
</RelativeLayout>
<android.support.design.widget.FloatingActionButton
android:id="#+id/reviewSerialFrag_FilterBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_margin="#dimen/padding15"
android:src="#drawable/ic_filter"
app:fabSize="normal" />
</RelativeLayout>
</android.support.v4.widget.NestedScrollView>
</android.support.v4.widget.DrawerLayout>
How can I fix this problem?
Hey man try this code :
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res-auto"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/toNightDrawerLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="end">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:id="#+id/reviewSerialFrag_newsCommentsLay"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="visible">
<android.support.v7.widget.CardView
android:id="#+id/reviewSerialFrag_newsCommentsCard"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="#dimen/padding8"
ads:cardBackgroundColor="#android:color/white"
ads:cardElevation="#dimen/size2"
app:contentPadding="#dimen/padding8">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:id="#+id/reviewSerialFrag_newsCommentsHeaderLay"
android:layout_width="match_parent"
android:layout_height="#dimen/size50">
<ImageView
android:id="#+id/reviewSerialFrag_newsCommentsHeaderImage"
android:layout_width="#dimen/size35"
android:layout_height="#dimen/size35"
android:layout_centerVertical="true"
android:alpha="0.8"
android:src="#drawable/ic_comments"
android:tint="#color/darkBlueGrey" />
<TextView
android:id="#+id/reviewSerialFrag_newsCommentsUserTypeText"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_margin="#dimen/padding10"
android:layout_toRightOf="#+id/reviewSerialFrag_newsCommentsHeaderImage"
android:fontFamily="sans-serif-light"
android:gravity="center_vertical"
android:textColor="#color/darkBlueGrey"
android:textSize="#dimen/font16" />
<TextView
android:id="#+id/reviewSerialFrag_newsCommentsReviewTypeText"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_margin="#dimen/padding10"
android:layout_toRightOf="#+id/reviewSerialFrag_newsCommentsUserTypeText"
android:fontFamily="sans-serif-light"
android:gravity="center_vertical"
android:textColor="#color/darkBlueGrey"
android:textSize="#dimen/font14" />
</RelativeLayout>
<android.support.v7.widget.RecyclerView
android:id="#+id/reviewSerialFrag_newsCommentsRecyclerView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/reviewSerialFrag_newsCommentsHeaderLay"
android:layout_marginTop="#dimen/padding5" />
</RelativeLayout>
</android.support.v7.widget.CardView>
</RelativeLayout>
<!--EmptyList-->
<RelativeLayout
android:id="#+id/reviewSerialFrag_EmptyLsy"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone">
<include layout="#layout/empty_list" />
</RelativeLayout>
</RelativeLayout>
</android.support.v4.widget.NestedScrollView>
<android.support.design.widget.FloatingActionButton
android:id="#+id/reviewSerialFrag_FilterBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_margin="#dimen/padding15"
android:src="#drawable/ic_filter"
app:fabSize="normal" />
</RelativeLayout>
</android.support.v4.widget.DrawerLayout>
So try do that:
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res-auto"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/toNightDrawerLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="end">
<android.support.design.widget.CoordinatorLayout
android:id="#+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:id="#+id/reviewSerialFrag_newsCommentsLay"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="visible">
<android.support.v7.widget.CardView
android:id="#+id/reviewSerialFrag_newsCommentsCard"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="#dimen/padding8"
ads:cardBackgroundColor="#android:color/white"
ads:cardElevation="#dimen/size2"
app:contentPadding="#dimen/padding8">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:id="#+id/reviewSerialFrag_newsCommentsHeaderLay"
android:layout_width="match_parent"
android:layout_height="#dimen/size50">
<ImageView
android:id="#+id/reviewSerialFrag_newsCommentsHeaderImage"
android:layout_width="#dimen/size35"
android:layout_height="#dimen/size35"
android:layout_centerVertical="true"
android:alpha="0.8"
android:src="#drawable/ic_comments"
android:tint="#color/darkBlueGrey" />
<TextView
android:id="#+id/reviewSerialFrag_newsCommentsUserTypeText"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_margin="#dimen/padding10"
android:layout_toRightOf="#+id/reviewSerialFrag_newsCommentsHeaderImage"
android:fontFamily="sans-serif-light"
android:gravity="center_vertical"
android:textColor="#color/darkBlueGrey"
android:textSize="#dimen/font16" />
<TextView
android:id="#+id/reviewSerialFrag_newsCommentsReviewTypeText"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_margin="#dimen/padding10"
android:layout_toRightOf="#+id/reviewSerialFrag_newsCommentsUserTypeText"
android:fontFamily="sans-serif-light"
android:gravity="center_vertical"
android:textColor="#color/darkBlueGrey"
android:textSize="#dimen/font14" />
</RelativeLayout>
<android.support.v7.widget.RecyclerView
android:id="#+id/reviewSerialFrag_newsCommentsRecyclerView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/reviewSerialFrag_newsCommentsHeaderLay"
android:layout_marginTop="#dimen/padding5" />
</RelativeLayout>
</android.support.v7.widget.CardView>
</RelativeLayout>
<!--EmptyList-->
<RelativeLayout
android:id="#+id/reviewSerialFrag_EmptyLsy"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone">
<include layout="#layout/empty_list" />
</RelativeLayout>
</RelativeLayout>
</android.support.v4.widget.NestedScrollView>
<android.support.design.widget.FloatingActionButton
android:id="#+id/reviewSerialFrag_FilterBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end|bottom"
android:layout_margin="#dimen/padding15"
android:src="#drawable/ic_filter"
app:fabSize="normal" />
</android.support.design.widget.CoordinatorLayout>
</android.support.v4.widget.DrawerLayout>
Set all contect inside a coordinator layout and fab outside the nestedscrollview .If not work ask me to send other possible way.
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/Widget.AppTheme.AppBarOverlay">
<include
layout="#layout/include_layout_toolbar_scroll"/>
</android.support.design.widget.AppBarLayout>
<include layout="#layout/include_layout_content_with_nestedscroll"/>
<android.support.design.widget.FloatingActionButton
android:id="#+id/fab_task_accept"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end|bottom"
android:layout_margin="#dimen/fab_margin"
android:src="#drawable/ic_accepted"
app:layout_behavior="pass.to.FabScrollBehavior.Class"
app:theme="#style/Widget.AppTheme.Fab"/>
< /android.support.design.widget.CoordinatorLayout>
use coordinatorlayout
use this link
So I have this fragment_list.xml inside a TabbedActivity. It has a ListView and a FloatingActionButton. But I don't know why, the fragment is a little bit cropped, so the ListView cannot be scrolled down until the bottom, and the FAB only shows a little bit.
Here's the picture of it. It is on the bottom of the scroll:
fragment_list.xml
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context="com.garudamaya.dennydap.lookingood.BlankFragment">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ProgressBar
android:id="#+id/listProgress"
android:layout_width="64dp"
android:layout_height="64dp"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"/>
<ListView
android:id="#+id/listView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:divider="#null"
android:dividerHeight="0dp">
</ListView>
</RelativeLayout>
<android.support.design.widget.FloatingActionButton
android:id="#+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|right|end"
android:layout_margin="#dimen/fab_margin"
android:background="#color/colorPrimaryDark"
app:srcCompat="#drawable/ic_sort_by_alpha_white_24px"
app:rippleColor="#FFF"/>
</FrameLayout>
fragment_tabbed.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="com.garudamaya.dennydap.lookingood.MainActivity$PlaceholderFragment">
<TextView
android:id="#+id/section_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
activity_tabbed.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:id="#+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="com.garudamaya.dennydap.lookingood.MainActivity">
<android.support.design.widget.AppBarLayout
android:id="#+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="#dimen/appbar_padding_top"
android:theme="#style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="#style/AppTheme.PopupOverlay">
</android.support.v7.widget.Toolbar>
<android.support.design.widget.TabLayout
android:id="#+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior" />
</android.support.design.widget.CoordinatorLayout>
Any ideas?
Try this,
<?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="fill_parent"
android:layout_height="fill_parent">
<ProgressBar
android:id="#+id/listProgress"
android:layout_width="64dp"
android:layout_height="64dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:visibility="gone" />
<android.support.v7.widget.RecyclerView
android:id="#+id/mRecyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:dividerHeight="0dp" />
<android.support.design.widget.FloatingActionButton
android:id="#+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_gravity="bottom|right|end"
android:layout_marginBottom="60dp"
android:layout_marginRight="8dp"
android:background="#color/colorPrimaryDark"
app:rippleColor="#FFF"
app:srcCompat="#drawable/ic_home_blue" />
</RelativeLayout>
Answer Is :- Solve Different Layout and waeight sum use to solver this problem
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="2">
<ListView
android:id="#+id/listView"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1.6"
android:divider="#null"
android:dividerHeight="0dp"></ListView>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.4">
<android.support.design.widget.FloatingActionButton
android:id="#+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_gravity="bottom|right"
android:background="#color/colorPrimaryDark"
app:rippleColor="#FFF"
app:srcCompat="#drawable/ic_sort_by_alpha_white_24px" />
</RelativeLayout>
</LinearLayout>
I hop this layout is perfect and solve this probolem
Good afternoon,
I am trying to put a FAB at the bottom|end of a fragment, but I do not know where I can place it.
Here is the Fragment's xml code :
<android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/swipe_container"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/cars_list_content"
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:id="#+id/scrollable_layout">
<include layout="#layout/write_comment"/>
<android.support.v7.widget.RecyclerView
android:id="#+id/recyclerview"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
</android.support.design.widget.CoordinatorLayout>
</android.support.v4.widget.SwipeRefreshLayout>
And the FAB :
<android.support.design.widget.FloatingActionButton
android:id="#+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end|bottom"
android:layout_margin="#dimen/fab_margin"
android:src="#drawable/ic_plus" />
Thanks for your help !
An answer helped me to have a first "solution" with this code :
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/swipe_container"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/cars_list_content"
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:id="#+id/scrollable_layout">
<include layout="#layout/write_comment"/>
<android.support.v7.widget.RecyclerView
android:id="#+id/recyclerview"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
</android.support.design.widget.CoordinatorLayout>
</android.support.v4.widget.SwipeRefreshLayout>
<android.support.design.widget.FloatingActionButton
android:id="#+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end|bottom"
android:layout_margin="#dimen/fab_margin"
android:src="#drawable/ic_plus"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"/>
</RelativeLayout>
But it does not work correctly :
Try this:
<?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:fitsSystemWindows="true">
<android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/swipe_container"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/cars_list_content"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="#+id/scrollable_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v7.widget.RecyclerView
android:id="#+id/recyclerview"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
</android.support.design.widget.CoordinatorLayout>
</android.support.v4.widget.SwipeRefreshLayout>
<android.support.design.widget.FloatingActionButton
android:id="#+id/fab_add"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_margin="#dimen/fab_margin"
android:src="#drawable/ic_photo_camera_white"
app:backgroundTint="#color/colorFabButton" />
</RelativeLayout>
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="#+id/image12"
android:layout_width="match_parent"
android:layout_height="250dp"
android:alpha="0.5"
android:src="#drawable/lawbook"
android:scaleType="fitXY"/>
<de.hdodenhof.circleimageview.CircleImageView
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/profile_image"
android:layout_width="120dp"
android:layout_height="120dp"
android:src="#drawable/aliyar"
android:layout_above="#+id/text121"
android:layout_centerHorizontal="true"
android:layout_marginBottom="71dp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/image12"
android:textSize="14sp"
android:layout_marginTop="40dp"
android:id="#+id/text121"
android:text="#string/aliyar1"
android:gravity="center_horizontal"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/text121"
android:layout_marginTop="5dp"
android:textSize="14sp"
android:text="#string/aliyar2"
android:id="#+id/text122"
android:gravity="center_horizontal"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/text122"
android:layout_marginTop="5dp"
android:text="#string/aliyar3"
android:textSize="14sp"
android:id="#+id/text123"
android:gravity="center_horizontal"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/text123"
android:layout_marginTop="5dp"
android:text="#string/aliyar4"
android:id="#+id/text124"
android:textSize="14sp"
android:gravity="center_horizontal"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/text124"
android:layout_marginTop="5dp"
android:text="#string/aliyar5"
android:id="#+id/text125"
android:textSize="14sp"
android:gravity="center_horizontal"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/text125"
android:layout_marginTop="5dp"
android:text="#string/aliyar6"
android:textSize="14sp"
android:id="#+id/text126"
android:gravity="center_horizontal"
/>
</RelativeLayout>
</ScrollView>
</RelativeLayout>
Check below Layout :
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 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"
android:id="#+id/contactnew">
<include
layout="#layout/contentcontact"/>
<android.support.design.widget.FloatingActionButton
android:id="#+id/facebookfab"
android:layout_gravity="bottom|right"
android:layout_width="299dp"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:clickable="true"
app:backgroundTint="#fff"
android:src="#mipmap/facebook" />
<android.support.design.widget.FloatingActionButton
android:id="#+id/callfab"
android:layout_gravity="bottom|left"
android:layout_width="299dp"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:clickable="true"
app:backgroundTint="#color/Color_Blue"
android:src="#drawable/ic_local_phone_black_24dp" />
</android.support.design.widget.CoordinatorLayout>