Android FAB not at right place - android

My Floating button is not aligned where I want it. I want it next to the InputBox but also a bit more down on the layout. It is currently a bit above the InputBox
I have seen the following Link and I have tried it but I could't get it working, Here is my layout
<?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:id="#+id/activity_chat"
android:layout_width="match_parent"
android:layout_height="match_parent">
<include
android:id="#+id/toolbar"
layout="#layout/toolbar" />
<RelativeLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/main_content"
android:padding="10dp"
android:focusable="true"
android:focusableInTouchMode="true"
android:layout_below="#id/toolbar">
<android.support.design.widget.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_send_black_24dp"
android:id="#+id/fsend"
android:clickable="true"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:tint="#android:color/white"
android:layout_gravity="bottom|right"
app:backgroundTint="#2196F3"
app:elevation="6dp"
app:fabSize="mini" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Write message here"
android:layout_toLeftOf="#+id/fsend"
android:background="#drawable/bubble_reciever"
android:layout_alignParentBottom="true"
android:layout_alignParentStart="true"
android:id="#+id/chat_input" />
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true"
android:layout_above="#id/fsend"
android:dividerHeight="16dp"
android:divider="#android:color/transparent"
android:id="#+id/list_of_messages"
android:layout_marginBottom="16dp" />
</RelativeLayout>
</RelativeLayout>
Here is a screenshot
EDIT 1:
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Write message here"
android:layout_toLeftOf="#+id/fsend"
android:background="#drawable/bubble_reciever"
android:layout_alignParentBottom="true"
android:layout_alignParentStart="true"
android:id="#+id/chat_input" />
<android.support.design.widget.FloatingActionButton
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_alignBaseline="#id/chat_input"
android:src="#drawable/ic_send_black_24dp"
android:id="#+id/fsend"
android:clickable="true"
android:tint="#android:color/white"
app:backgroundTint="#2196F3"
app:fabSize="mini" />

I think if you add android:layout_alignBaseline="#id/chat_input" in your fab view it would do the work.
ATTENTION : you must swap the position of your fab and your edittext in your xml file.

Related

How to make Float Action Button at right of bottom of the page

I just created a Float Action button and put the attributes aliign parent bottom and right but it doesn't shown I don't know what I did wrong exactly here's my xml code................................................
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/activity_show_order"
android:layout_width="368dp"
android:layout_height="624dp"
tools:layout_editor_absoluteX="0dp"
tools:layout_editor_absoluteY="0dp"
tools:context="abtech.waiteriano.com.waitrer.PaymentActivity">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="60dp"
android:background="#f0ff4800"
android:minHeight="?attr/actionBarSize" />
<ListView
android:layout_width="fill_parent"
android:id="#+id/showOrderListID"
android:layout_height="wrap_content"
tools:layout_editor_absoluteY="8dp"
tools:layout_editor_absoluteX="8dp"
android:layout_alignParentStart="true"
android:layout_below="#id/toolbar"/>
<TextView
android:id="#+id/tvPayment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/showOrderListID"
android:text="Payment Type:" />
<Spinner
android:id="#+id/paymentSpinner"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:background="#drawable/spinner_bg"
android:stateListAnimator="#drawable/spinner_sla"
android:layout_below="#+id/showOrderListID"
android:layout_alignBottom="#+id/tvPayment"
android:layout_toEndOf="#+id/tvPayment" />
<android.support.design.widget.FloatingActionButton
android:id="#+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:src="#drawable/pay" />
</RelativeLayout>
use this layout:
Remove height , width declaration and use match_parent attribute..and use FrameLayout as a Root layout.
<?xml version="1.0" encoding="utf-8"?>
<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/activity_show_order"
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.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="60dp"
android:background="#f0ff4800"
android:minHeight="?attr/actionBarSize" />
<ListView
android:id="#+id/showOrderListID"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_below="#id/toolbar"
tools:layout_editor_absoluteX="8dp"
tools:layout_editor_absoluteY="8dp" />
<TextView
android:id="#+id/tvPayment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/showOrderListID"
android:text="Payment Type:" />
<Spinner
android:id="#+id/paymentSpinner"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/tvPayment"
android:layout_below="#+id/showOrderListID"
android:layout_toEndOf="#+id/tvPayment"
android:background="#drawable/bottom_border_help"
android:stateListAnimator="#drawable/bottom_border_help" />
</LinearLayout>
<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|end"
android:src="#mipmap/ic_launcher" />
</FrameLayout>
<android.support.design.widget.FloatingActionButton xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/fbLiveAccount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_marginBottom="#dimen/scale_16dp"
android:layout_marginEnd="#dimen/scale_16dp"
android:layout_marginRight="#dimen/scale_16dp"
android:clickable="true"
android:src="#drawable/ic_add_black_24dp"
app:backgroundTint="#color/color_f27f17" />

Extra whitespace between android Views

In the following layout , after the AppBarLayout and before RecyclerView , some extra whitespace is coming , i am unable to figure out how it is coming.
I've checked margins and all , seems to be fine .
Also due to same reason , i believe the last element of RecyclerView is cropped out of the layout view .
Any help appreciated .
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/transMain"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<android.support.design.widget.AppBarLayout
android:id="#+id/app_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
android:theme="#style/AppTheme.AppBarOverlay">
<android.support.design.widget.CollapsingToolbarLayout
android:id="#+id/toolbar_layout"
android:layout_width="match_parent"
android:layout_height="80dp"
android:fitsSystemWindows="true"
android:paddingLeft="12dp"
app:contentScrim="?android:attr/colorPrimary"
app:layout_scrollFlags="exitUntilCollapsed">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbarAct"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/colorPrimary"
app:layout_scrollFlags="scroll">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<!--button was here-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<RelativeLayout
android:id="#+id/monthSelLay"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="#+id/monthButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:textColor="#000"
android:textSize="14sp" />
<ImageView
android:layout_width="22dp"
android:layout_height="22dp"
android:layout_marginTop="12dp"
android:layout_toRightOf="#id/monthButton"
android:src="#drawable/ic_keyboard_arrow_down_black_24dp" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/syncLay"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="#+id/syncButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="50dp"
android:layout_marginTop="8dp"
android:text="SyncUp"
android:textAlignment="center"
android:textColor="#000" />
<ImageView
android:layout_width="22dp"
android:layout_height="22dp"
android:layout_marginTop="5dp"
android:layout_toRightOf="#+id/syncButton"
android:src="#drawable/ic_cached_black_48dp" />
</RelativeLayout>
</LinearLayout>
<!--switch was here-->
</RelativeLayout>
</android.support.v7.widget.Toolbar>
</android.support.design.widget.CollapsingToolbarLayout>
<android.support.v7.widget.SearchView
android:id="#+id/searchTrans"
android:layout_width="350dp"
android:layout_height="40dp"
android:layout_below="#+id/toolbar"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="10dp"
android:layout_marginTop="10dp"
android:background="#fff"
android:hint="Start typing an Amount/Description"
android:textColor="#000"
android:textColorHint="#ccc"
app:tabMode="scrollable" />
<!--need to change the background as an object oval prbbly-->
</android.support.design.widget.AppBarLayout>
<android.support.v7.widget.RecyclerView
android:id="#+id/trans"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_horizontal"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
</android.support.v7.widget.RecyclerView>
</android.support.design.widget.CoordinatorLayout>
<android.support.design.widget.FloatingActionButton
android:id="#+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="#dimen/fab_margin"
android:src="#drawable/ic_add_black_24dp"
app:backgroundTint="#color/colorAccent"
app:elevation="6dp"
app:pressedTranslationZ="12dp" />
</FrameLayout>
In the first image , i've scrolled up slightly to show the whitespace.
With cropped last element of RecyclerView .
Remove this line from your RecyclerView
android:layout_gravity="center_horizontal"
Remove this line:
android:layout_gravity="center_horizontal"
or
Make your coordinator height to wrap_content.
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/transMain"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true">

EmptyView of ListView hides BottomNavigationView

I have an AppCompatActivity with a listview with the layout below
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
android:id="#+id/main_content"
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">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/user_title"
android:background="#drawable/user_title_color"
android:textColor="#android:color/white"
android:textAppearance="#android:style/TextAppearance.Large"/>
<ListView android:id="#+id/joggings_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:divider="#b5b5b5"
android:dividerHeight="1dp"
android:drawSelectorOnTop="false"/>
<LinearLayout
android:id="#+id/empty_list"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_vertical|center">
<TextView
android:text="No joggings yet"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<Button
android:id="#+id/empty_add_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Add"/>
</LinearLayout>
<android.support.design.widget.FloatingActionButton
android:id="#+id/add_jogging"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/bottom_navigation"
android:layout_alignParentRight="true"
android:layout_gravity="end|bottom"
android:layout_marginBottom="16dp"
android:layout_marginRight="16dp"
android:clickable="true"
android:src="#drawable/ic_plus"
app:borderWidth="0dp" />
<android.support.design.widget.BottomNavigationView
android:id="#+id/bottom_navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:background="#color/colorPrimaryDark"
android:foregroundTint="#color/colorAccent"
app:itemTextColor="#color/bottom_navigation_color"
app:itemIconTint="#color/bottom_navigation_color"
app:menu="#menu/bottom_navigation_main" />
</LinearLayout>
</android.support.design.widget.CoordinatorLayout>
and in my code I have
mListView.setEmptyView(findViewById(R.id.empty_list));
in order to display a message and an "add" button when the list is empty. My problem is that when the list is empty the BottomNavigationView is hidden and the user cannot navigate to another activity.
One possible solution I can think of is to add another BottomNavigationView with the same items in the empty layout but that seems ugly.
Any other solution?
Set empty_list height to wrap_content
Your ListView and it's empty view should have the same layout attributes if you want them to occupy the same space. In your case, they should both be
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
Also, you should put the FloatingActionButton outside of the LinearLayout, or else it will affect the size of your ListView/empty view. It is also meant to be a direct child of CoordinatorLayout, otherwise its default behaviors do not work.
The following layout worked fine. The basic idea is that coordinateLayout contains listview and FloatingActionButton and empty view. CoordinateLayout is contained in an outer vertical LinearLayout which also contains the header textview and the BottomNavigationView
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="#+id/user_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/user_title_color"
android:textAppearance="#android:style/TextAppearance.Large"
android:textColor="#android:color/white" />
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/main_content"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<ListView
android:id="#+id/joggings_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:divider="#b5b5b5"
android:dividerHeight="1dp"
android:drawSelectorOnTop="false" />
<android.support.design.widget.FloatingActionButton
android:id="#+id/add_jogging"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/bottom_navigation"
android:layout_alignParentRight="true"
android:layout_gravity="end|bottom"
android:layout_marginBottom="16dp"
android:layout_marginRight="16dp"
android:clickable="true"
android:src="#drawable/ic_plus"
app:borderWidth="0dp"
app:layout_anchor="#id/joggings_list"
app:layout_anchorGravity="bottom|right|end" />
<LinearLayout
android:id="#+id/empty_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_vertical|center"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="No joggings yet" />
<Button
android:id="#+id/empty_add_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Add" />
</LinearLayout>
</android.support.design.widget.CoordinatorLayout>
<android.support.design.widget.BottomNavigationView
android:id="#+id/bottom_navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:background="#color/colorPrimaryDark"
android:foregroundTint="#color/colorAccent"
app:itemIconTint="#color/bottom_navigation_color"
app:itemTextColor="#color/bottom_navigation_color"
app:menu="#menu/bottom_navigation_main" />
</LinearLayout>

fitSystemWindows not working in a coordinated layout

I have implemented a ViewPager Activity (see layout below). The problem is navigationTabBar is always hidden.
With no luck, I have tried tinkering with fitSystemWindows.
Layout:
<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:id="#+id/tabbed_main"
android:background="#FFFFFF"
android:screenOrientation="portrait"
xmlns:fab="http://schemas.android.com/apk/res-auto">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:isScrollContainer="true"
android:scrollbars="none">
<android.support.v4.view.ViewPager
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/vp_horizontal_ntb"
android:gravity="center"
android:paddingLeft="0dp"
android:paddingRight="0dp"
app:layout_behavior="#string/appbar_scrolling_view_behavior" />
</LinearLayout>
</RelativeLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:fitsSystemWindows="true">
<com.gigamole.navigationtabbar.ntb.NavigationTabBar
android:layout_width="match_parent"
android:layout_height="60dp"
android:id="#+id/ntb_horizontal"
app:ntb_badge_size="12sp"
app:ntb_badge_bg_color="#ffff0000"
app:ntb_badge_gravity="top"
app:ntb_badge_position="right"
app:ntb_badge_title_color="#ffffffff"
app:ntb_badge_use_typeface="true"
app:ntb_badged="true"
app:ntb_animation_duration="400" />
</LinearLayout>
<com.getbase.floatingactionbutton.FloatingActionsMenu
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:id="#+id/create_new_button"
android:layout_marginBottom="60dp"
android:layout_marginRight="16dp"
android:layout_marginEnd="16dp"
fab:fab_addButtonColorNormal="#color/white_add"
fab:fab_addButtonColorPressed="#color/white_pressed"
fab:fab_addButtonPlusIconColor="#color/half_black"
fab:fab_labelStyle="#style/menu_labels_style">
<com.getbase.floatingactionbutton.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/action_create_post"
fab:fab_colorNormal="#color/white_add"
fab:fab_title="Create New Post"
fab:fab_icon="#drawable/ic_create_black_24dp"
fab:fab_colorPressed="#color/white_pressed"/>
<com.getbase.floatingactionbutton.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/action_create_new_message"
fab:fab_colorNormal="#color/white_add"
fab:fab_title="Write New Message"
fab:fab_icon="#drawable/ic_insert_comment_black_24dp"
fab:fab_colorPressed="#color/white_pressed"/>
<com.getbase.floatingactionbutton.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/action_upload_new_album"
fab:fab_colorNormal="#color/white_add"
fab:fab_title="Upload New Album"
fab:fab_icon="#drawable/ic_add_a_photo_black_24dp"
fab:fab_colorPressed="#color/white_pressed"/>
</com.getbase.floatingactionbutton.FloatingActionsMenu>
</android.support.design.widget.CoordinatorLayout>
N.B.- This topic has been discussed link goes here, and here; They all seem have not solve my problem.
Update: Add screenshot.
screenshot
Remove the RelativeLayout and put the NavigationTabBar inside the same LinearLayout as the ViewPager. Set the ViewPagers height to 0 with layout_height="0dp" and add a weigth of 1 with layout_weigth="1". The layout should look something like this:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
....>
<com.gigamole.navigationtabbar.ntb.NavigationTabBar
android:layout_width="match_parent"
android:layout_height="60dp"
... />
<android.support.v4.view.ViewPager
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weigth="1"
... />
</LinearLayout>

Cannot position floating action button to bottom right of the screen

For a strange reason my floating action button wont go down to the lower right portion of my android activity which is suppose to be its default behavior.
What did I do wrong in my layout.xml ?
<android.support.design.widget.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end|bottom"
android:layout_margin="16dp"
android:clickable="true"
android:src="#android:drawable/ic_menu_myplaces" />
BELOW IS MY WHOLE LAYOUT
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="100dp"
android:paddingBottom="#dimen/activity_vertical_margin"
app:layout_behavior="#string/appbar_scrolling_view_behavior" tools:showIn="#layout/app_bar_main"
tools:context=".MainActivity"
android:elevation=".5dp"
android:background="#drawable/trizbg"
android:focusable="true">
<ImageView
android:id="#+id/imgLogo"
android:layout_width="250dp"
android:layout_height="150dp"
android:src="#drawable/h_biglogo"
android:paddingTop="8.5dp"
android:paddingBottom="8.5dp"
android:paddingLeft="12dp"
android:paddingRight="12dp"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignRight="#+id/hiaTextField"
android:layout_alignEnd="#+id/hiaTextField"
android:layout_above="#+id/hiaTextField" />
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/hiaTextField"
android:selectAllOnFocus="true"
android:textColorHint="#ffffffff"
android:hint="Tell us where you're going"
android:drawableLeft="#android:drawable/ic_search_category_default"
android:text=""
android:autoText="false"
android:layout_gravity="center_horizontal|bottom"
android:padding="12dip"
android:background="#AA000000"
android:textColor="#ffffffff"
android:layout_centerVertical="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="SEARCH"
android:id="#+id/hiaButton"
android:onClick="hiaSubmitClick"
android:paddingTop="8dp"
android:paddingBottom="8dp"
android:layout_below="#+id/hiaTextField"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:textSize="18sp"
android:textColor="#color/colorWhite"
android:alpha="20"
android:layout_alignRight="#+id/hiaTextField"
android:layout_alignEnd="#+id/hiaTextField"
android:background="#drawable/buttonround"/>
<android.support.design.widget.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_margin="16dp"
android:clickable="true"
android:src="#android:drawable/ic_menu_myplaces" />
</RelativeLayout>
Below is the screenshot
General template for getting the FAB at the bottom right is to include your layout inside of a CoordinatorLayout, then have the button to aligned to the buttom-right of that.
I think your problem is that the layout_gravity attribute doesn't apply to RelativeLayout children.
You could do this, but that isn't really the documented way it should be done.
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
What you should have is like so, of course, replacing that include line with the name of your layout.
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="com.androidstack.app.NavDrawerActivity2">
<android.support.design.widget.AppBarLayout
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:theme="#style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="#style/AppTheme.PopupOverlay"/>
</android.support.design.widget.AppBarLayout>
<include layout="#layout/your_layout"/>
<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:src="#android:drawable/ic_menu_myplaces"/>
</android.support.design.widget.CoordinatorLayout>
Try to add this attribute for floating action button
app:layout_anchor="#id/layout" //id of the relativelayout
app:layout_anchorGravity="bottom|right|end"

Categories

Resources