I have to make (sort of) footer for empty screen. My parent layout is RelativeLayout1. Inside this layout I have ToolBar and below that is another RelativeLayout2.
Inside this RelativeLayout2 is Button and another RelativeLayout3. I made it that way, because I want to center RelativeLayout3 content in RelativeLayout2 and Button should always align bottom of the parent layout(RelativeLayout2)
I got answer for similar question before, but it doesnt always work. My problem now is that RelativeLayout3 is off-centered vertically(it's closer to the bottom).
How it should looks like
How it actually looks like
How to fix this?
Full Layout:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:background="#color/colorBackground"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.Toolbar
android:id="#+id/toolBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/toolbar_round"
android:orientation="horizontal">
<include
android:id="#+id/toolBarContent"
layout="#layout/order_toolbar_layout" />
</android.support.v7.widget.Toolbar>
<RelativeLayout
android:id="#+id/order_complete_footer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#id/toolBar"
android:gravity="center"
android:orientation="vertical">
<RelativeLayout
android:id="#+id/order_complete_image_text_layout"
android:layout_centerInParent="true"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<ImageView
android:id="#+id/order_complete_image"
android:layout_width="175dp"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_marginEnd="16dp"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:src="#drawable/footer_image" />
<TextView
android:id="#+id/order_complete_text1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/order_complete_image"
android:layout_marginEnd="50dp"
android:layout_marginStart="50dp"
android:layout_marginTop="-12dp"
android:gravity="center_horizontal"
android:text="#string/order_complete_screen_text1"
android:textColor="#color/colorItemMinor"
android:textStyle="bold"
android:textSize="12sp" />
<TextView
android:id="#+id/order_complete_text2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/order_complete_text1"
android:layout_marginEnd="50dp"
android:layout_marginStart="50dp"
android:gravity="center_horizontal"
android:text="#string/order_complete_screen_text2"
android:textColor="#color/colorItemMinor"
android:textSize="12sp" />
</RelativeLayout>
<Button
android:id="#+id/order_complete_continue_button"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_alignParentBottom="true"
android:layout_marginBottom="#dimen/address_creation_button_padding_TOP_BOTTOM"
android:layout_marginEnd="#dimen/address_creation_button_padding_START_END"
android:layout_marginStart="#dimen/address_creation_button_padding_START_END"
android:layout_marginTop="#dimen/address_creation_button_padding_TOP_BOTTOM"
android:background="#drawable/login_button_background_void"
android:text="#string/order_complete_screen_button_label"
android:textAppearance="#style/VoidLoginButtonTextAppearance" />
</RelativeLayout>
</RelativeLayout>
If I understood correctly, you should add the following to your order_complete_image_text_layout.
android:layout_above="#id/order_complete_continue_button"
#JanStoltman
Related
I have a Button which is aligned at the bottom of my screen. This Button lifts up when the SoftKeyboard is opened. The page is blank in the middle. But it has some content at the top and some right above the bottom aligned Button. The problem is when the SoftKeyboard is opened, the blank area in the middle is filled with the content in the bottom. What I want instead is, the bottom content to stay where it was and be able to scroll behind to see it.
Use the below property for your activity in android manifest. So that screen component can be accessible even after after soft keyboard opened.
<activity
android:windowSoftInputMode="adjustResize" ... >
...
</activity>
Reference Link: https://developer.android.com/training/keyboard-input/visibility#Respond
For someone facing the same problem, I solved it this way
<?xml version="1.0" encoding="utf-8"?>
<layout 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">
<data>
<!--data binding declaration-->
</data>
<RelativeLayout
android:id="#+id/register_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/primary_amber_200"
tools:context=".login.view.EnterEmailActivity">
<LinearLayout
android:id="#+id/register_ll"
android:layout_width="match_parent"
android:layout_height="92dp"
android:orientation="vertical"
android:layout_alignParentBottom="true"
android:gravity="center">
<View
android:id="#+id/register_bar"
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#color/primary_amber_100"
android:layout_marginBottom="12dp"
android:visibility="invisible"/>
<Button
android:id="#+id/register_loginBtn"
style="#style/Button_Default_Dark_Grey"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="#dimen/margin_small"
android:fitsSystemWindows="true"
android:text="#string/next"
android:layout_marginLeft="#dimen/margin_medium"
android:layout_marginRight="#dimen/margin_medium"/>
</LinearLayout>
<androidx.appcompat.widget.Toolbar
style="#style/ToolBar_Basic_Light"
android:background="#color/primary_amber_200"
android:elevation="0dp"
android:paddingLeft="#dimen/margin_medium"
android:paddingRight="#dimen/margin_medium">
<TextView
android:id="#+id/toolbar_title"
style="#style/Text_Basic_Toolbar" />
</androidx.appcompat.widget.Toolbar>
<ScrollView
android:id="#+id/register_sv"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
android:scrollbars="none"
android:layout_below="#id/toolbar"
android:paddingLeft="#dimen/margin_medium"
android:paddingRight="#dimen/margin_medium"
android:layout_marginBottom="#dimen/margin_xlarge92">
<RelativeLayout
android:id="#+id/register_rl"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/register_txtHeader"
style="#style/Text_Title_H1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/margin_large"
android:text="#string/enter_email" />
<EditText
android:id="#+id/register_email"
android:layout_width="match_parent"
android:layout_height="56dp"
android:layout_below="#id/register_txtHeader"
android:layout_marginTop="#dimen/margin_xlarge"
android:background="#color/primary_amber_100"
android:gravity="center_vertical"
android:hint="#string/email"
android:inputType="textEmailAddress"
android:paddingLeft="#dimen/margin_medium"
android:paddingRight="#dimen/margin_small" />
<View
android:id="#+id/register_blank"
android:layout_width="match_parent"
android:layout_height="300dp"
android:layout_below="#id/register_email"
/>
<RelativeLayout
android:id="#+id/register_bottom_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="#dimen/margin_small"
android:layout_below="#id/register_blank"
android:layout_marginTop="#dimen/margin_xxxlarge"
android:gravity="bottom"
android:layout_alignParentBottom="true">
<TextView
android:id="#+id/register_agreetxt"
style="#style/Text_Body_2"
android:textColor="#color/secondary_grey_800"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="bottom"
android:text="#string/agree" />
<TextView
android:id="#+id/register_terms"
style="#style/Text_Button_Normal"
android:layout_width="wrap_content"
android:layout_height="48dp"
android:layout_below="#id/register_agreetxt"
android:text="#string/terms"
android:gravity="center"/>
<TextView
android:id="#+id/register_policy"
style="#style/Text_Button_Normal"
android:layout_width="wrap_content"
android:layout_height="48dp"
android:layout_below="#id/register_agreetxt"
android:layout_marginLeft="#dimen/margin_xlarge"
android:layout_toRightOf="#id/register_terms"
android:text="#string/policy"
android:gravity="center_vertical"/>
<TextView
android:id="#+id/register_have_accnt"
style="#style/Text_Body_2"
android:textColor="#color/secondary_grey_800"
android:layout_width="wrap_content"
android:layout_height="48dp"
android:layout_below="#id/register_terms"
android:text="#string/already_have_an_account"
android:gravity="center"/>
<TextView
android:id="#+id/register_login"
style="#style/Text_Button_Normal"
android:layout_width="wrap_content"
android:layout_height="48dp"
android:layout_below="#id/register_terms"
android:layout_marginLeft="#dimen/margin_xlarge"
android:layout_toRightOf="#id/register_have_accnt"
android:text="#string/login"
android:gravity="center"/>
</RelativeLayout>
</RelativeLayout>
</ScrollView>
</RelativeLayout>
</layout>
Dont forget to add android:windowSoftInputMode="stateVisible|adjustResize" to your activity in your manifest file.
I am trying to place a relativelayout under another (with recyclerview in it) within an activity layout container.
What I'd like to get is to have the action bar, then below a relativelayout with header (showing a spacer and 2 textviews), and below again another relativelayout that will host cards from a recyclerview.
This is the image of the wanted design:
What I get instead is this:
I am using the following xml (but tried many others)
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:theme="#style/Theme.AppCompat.Light">
<RelativeLayout
android:id="#+id/header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
tools:ignore="UselessParent">
<ImageView
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_centerInParent="true"
android:contentDescription="image"
android:scaleType="centerCrop"
android:src="#drawable/category_detail_1" />
<TextView
android:id="#+id/spacer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingEnd="5dp"
android:paddingStart="5dp"
android:text=""
android:textColor="#fff"
android:textSize="25sp" />
<TextView
android:id="#+id/sub_header_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/spacer"
android:background="#66555555"
android:paddingEnd="5dp"
android:paddingStart="5dp"
android:text=""
android:textColor="#fff"
android:textSize="30sp"
android:textStyle="bold" />
<TextView
android:id="#+id/sub_header_description"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/sub_header_title"
android:background="#66555555"
android:paddingEnd="5dp"
android:paddingStart="5dp"
android:text=""
android:textColor="#fff"
android:textSize="20sp" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/button_container"
android:layout_width="395dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:orientation="vertical"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/header"
tools:ignore="UselessParent">
<android.support.v4.widget.Space
android:layout_width="#dimen/default_spacing_small"
android:layout_height="#dimen/default_spacing_small" />
</RelativeLayout>
</android.support.constraint.ConstraintLayout>
I tried to put the second RelativeLayout nested as a child of the first one with no luck.
The Android Studio preview shows the design well formatted but after build the card list overlaps the header. Well formatted apart from the unknown line/constraint I do not know how to remove. It constraints the second relativelayout to the top.
What am I missing?
Any help is appreciated.
Use FrameLayout instead of android.support.constraint.ConstraintLayout
Or try with LinearLayout
Basicly i created all my layouts with a library that is already deprecated (PercentRelativeLayout) everything works well except that i have this layout inside a ScrollView, and the scroll doesn't work on all devices.
I read some topics about it and seems the issue is with the Percent Library.
So i need to move on and construct the Lienar Layout example, i tried to construct my layout with the current Layout that i have but everything got buggy, the spaces between the elements are never the same as i had with the percent.
Basicly what i need is this:
The elements are top down -> toolbar -> thumbnail -> recycle view(this one just has a unique image -> details about this foto.
I have more details about it, but if i can construct this example its fine.
so my xml that i current have is this:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView 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:fillViewport="true">
<LinearLayout android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.percent.PercentRelativeLayout 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.support.design.widget.FloatingActionButton
android:id="#+id/fab"
app:srcCompat="#android:drawable/ic_menu_camera"
android:elevation="2dp"
app:layout_widthPercent="90%"
app:layout_heightPercent="10%"
app:layout_marginTopPercent="90%"
app:layout_marginLeftPercent="80%"
app:backgroundTint="#f1c40f"
android:onClick="capture"/>
<include
layout="#layout/custom_toolbar"
android:id="#+id/my_toolbar"
app:layout_widthPercent="100%"
app:layout_heightPercent="8%"
app:layout_marginTopPercent="0%"
app:layout_marginLeftPercent="0%"/>
<com.example.afcosta.inesctec.pt.android.Helpers.OpenSansMedium
android:id="#+id/SpecieName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#color/nephritis"
android:textSize="14dp"
app:layout_widthPercent="60%"
app:layout_heightPercent="5%"
app:layout_marginTopPercent="85%"
app:layout_marginLeftPercent="30%"/>
<com.example.afcosta.inesctec.pt.android.Helpers.OpenSansMedium
android:id="#+id/GenreName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="genrePressed"
android:textColor="#color/nephritis"
android:textSize="14dp"
app:layout_widthPercent="60%"
app:layout_heightPercent="5%"
app:layout_marginTopPercent="95%"
app:layout_marginLeftPercent="30%"/>
<com.example.afcosta.inesctec.pt.android.Helpers.OpenSansMedium
android:id="#+id/FamilyName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="familyPressed"
android:textColor="#color/nephritis"
android:textSize="14dp"
app:layout_widthPercent="60%"
app:layout_heightPercent="5%"
app:layout_marginTopPercent="105%"
app:layout_marginLeftPercent="30%"/>
<com.example.afcosta.inesctec.pt.android.Helpers.OpenSansMedium
android:id="#+id/textView8"
android:text="Espécie"
android:textSize="14dp"
app:layout_widthPercent="25%"
app:layout_heightPercent="5%"
app:layout_marginTopPercent="85%"
app:layout_marginLeftPercent="5%"
/>
<com.example.afcosta.inesctec.pt.android.Helpers.OpenSansMedium
android:id="#+id/textView7"
app:layout_widthPercent="25%"
app:layout_heightPercent="5%"
app:layout_marginTopPercent="95%"
app:layout_marginLeftPercent="5%"
android:text="Género"
android:textSize="14dp" />
<com.example.afcosta.inesctec.pt.android.Helpers.OpenSansMedium
android:id="#+id/Family"
app:layout_widthPercent="25%"
app:layout_heightPercent="5%"
app:layout_marginTopPercent="105%"
app:layout_marginLeftPercent="5%"
android:text="Familia"
android:textSize="14dp" />
<com.example.afcosta.inesctec.pt.android.Helpers.OpenSansMedium
android:id="#+id/specieDescription"
android:textSize="14dp"
app:layout_widthPercent="90%"
android:layout_height="wrap_content"
app:layout_marginTopPercent="120%"
app:layout_marginLeftPercent="5%"/>
<com.example.afcosta.inesctec.pt.android.Helpers.OpenSansMedium
android:id="#+id/descricaoTit"
android:text="Descrição"
android:textSize="14dp"
app:layout_widthPercent="30%"
app:layout_heightPercent="5%"
app:layout_marginTopPercent="115%"
app:layout_marginLeftPercent="5%"/>
<ImageView
android:id="#+id/plantImage"
android:adjustViewBounds="true"
android:scaleType="fitXY"
app:layout_widthPercent="80%"
app:layout_heightPercent="50%"
app:layout_marginTopPercent="12%"
app:layout_marginLeftPercent="10%"
app:srcCompat="#drawable/color_cursor_white" />
<android.support.v7.widget.RecyclerView
android:id="#+id/gallery"
app:layout_widthPercent="100%"
app:layout_heightPercent="10%"
app:layout_marginTopPercent="62%"
app:layout_marginLeftPercent="0%" />
<RelativeLayout
app:layout_widthPercent="40%"
app:layout_heightPercent="5%"
app:layout_marginTopPercent="75%"
app:layout_marginLeftPercent="5%"
android:onClick="showMap">
<com.example.afcosta.inesctec.pt.android.Helpers.OpenSansMedium
android:id="#+id/googleMapsText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#+id/imageView6"
android:layout_alignBottom="#+id/imageView6"
android:text="Ver no mapa" />
<ImageView
android:id="#+id/imageView6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_facebook_placeholder_for_locate_places_on_maps"
android:tint="#F90101" />
</RelativeLayout>
</android.support.percent.PercentRelativeLayout>
</LinearLayout>
</ScrollView>
First for solving your problem with ScrollView you must know ScrollView works if you put a LinearLayout to be child of it and then cut all your Views inside this LinearLayout .
See this tree :
| ScrollView
|-- LinearLayout
|---- OtherViews you want to scroll
Its not important what you want to put Scrolling . you must follow this way.
EDIT :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
// everything you want to scroll
</LinearLayout>
</ScrollView>
</LinearLayout>
Sounds like a question that was answered before but from my research I couldn't find a solution. My layout is roughly the following:
The main area is a container where I'll add/replace Fragments, and the bottom is where I place a bottom navigation menu. The pink View is a button that I need to place on top of my menu (and that's not working).
Every time I add a Fragment to the main view, my "Menu" text disappears, even though the TextView is added after the container View. Same with the pink Button, which is added after the bottom menu container (see my xml below).
How can I keep both "Menu" TextView and the pink Button always on top of my Fragments?
This is my 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:background="#eee"
tools:context="com.wecancer.wecancer.activities.Menu">
<FrameLayout
android:id="#+id/main_container_view"
android:layout_width="match_parent"
android:layout_height="520dp"
android:layout_marginBottom="0dp"
>
</FrameLayout>
<TextView
android:id="#+id/main_center_tv"
android:layout_centerVertical="true"
android:textSize="24sp"
android:layout_centerHorizontal="true"
android:text="#string/menu"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<FrameLayout
android:layout_alignParentBottom="true"
android:id="#+id/main_bottom_menu_container"
android:layout_width="match_parent"
android:background="#color/lightGray"
android:layout_height="40dp"
>
</FrameLayout>
<Button
android:elevation="1dp"
android:id="#+id/menu_plus_img"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
android:background="#color/colorAccent"
android:layout_width="70dp"
android:layout_marginBottom="0dp"
android:layout_height="70dp"
tools:targetApi="lollipop" />
</RelativeLayout>
Try This`
<FrameLayout
android:layout_alignParentBottom="true"
android:id="#+id/main_bottom_menu_container"
android:layout_width="match_parent"
android:background="#color/colorPrimary"
android:layout_height="40dp"
>
</FrameLayout>
<Button
android:elevation="1dp"
android:id="#+id/menu_plus_img"
android:background="#color/colorAccent"
android:layout_width="70dp"
android:layout_height="70dp"
tools:targetApi="lollipop"
android:layout_marginLeft="71dp"
android:layout_marginStart="71dp"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<TextView
android:id="#+id/main_center_tv"
android:textSize="24sp"
android:text="#string/menu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:layout_marginStart="16dp"
android:layout_alignBaseline="#+id/menu_plus_img"
android:layout_alignBottom="#+id/menu_plus_img"
android:layout_toRightOf="#+id/menu_plus_img"
android:layout_toEndOf="#+id/menu_plus_img" />
<FrameLayout
android:id="#+id/main_container_view"
android:layout_width="match_parent"
android:layout_height="520dp"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="#+id/menu_plus_img">
</FrameLayout>
`
You just have to change the order of the views in the layout while using a Framelayout
The complexity of your layout does not require a RelativeLayout so you just have to switch.
I don't really know why methods like bringToFront, bringChildToFront, or adding and removing View's children to change their indices didn't work. So I actually had to create a new layout structure.
Instead of:
RelativeLayout
...FrameLayout
...TextView
...FrameLayout
...Button
I did:
FrameLayout
...RelativeLayout
......FrameLayout
......FrameLayout
......TextView
...RelativeLayout
......Button
Whereas the second RelativeLayout has only a button and a transparent background. My full xml code is below as a reference.
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/main_root_view"
android:layout_height="match_parent">
<RelativeLayout
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#eee"
tools:context="com.wecancer.wecancer.activities.Menu">
<FrameLayout
android:layout_alignParentBottom="true"
android:id="#+id/main_bottom_menu_container"
android:layout_width="match_parent"
android:background="#color/lightGray"
android:layout_height="wrap_content" />
<FrameLayout
android:id="#+id/main_container_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="0dp" />
<TextView
android:id="#+id/main_center_tv"
android:layout_centerVertical="true"
android:textSize="24sp"
android:layout_centerHorizontal="true"
android:text="#string/menu"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:onClick="menuPlusBt"
android:elevation="5dp"
android:id="#+id/menu_plus_img"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
android:background="#drawable/green_circle"
android:layout_width="70dp"
android:layout_marginBottom="0dp"
android:layout_height="70dp"
tools:targetApi="lollipop" />
</RelativeLayout>
</FrameLayout>
How can i position floating button above Scrollview layout...i have tried to position Scrollview and the container of the button(FrameLayout) inside Relative layout but this approach also is not working...
xml file:
<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"
android:weightSum="100">
<ScrollView
android:layout_width="match_parent"
android:layout_height="#dimen/no_size"
android:layout_weight="92">
<LinearLayout
android:id="#+id/questionContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<com.rey.material.widget.TextView
android:id="#+id/surveyTitleTtv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="12dp"
android:textSize="20sp"
android:textStyle="bold"
android:textColor="#android:color/black" />
<com.rey.material.widget.TextView
android:id="#+id/test"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="12dp"
android:layout_marginLeft="12dp"
android:layout_marginBottom="12dp"
android:textColor="#color/accentColor"
android:textSize="17dp"
android:textStyle="bold" />
</LinearLayout>
</ScrollView>
<FrameLayout
android:id="#+id/bottomSheetLlt"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_weight="8"
android:background="#android:color/white">
<com.rey.material.widget.FloatingActionButton
android:id="#+id/saveQuestionBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:layout_marginTop="-20dp"
android:text="ADD"
app:elevation="2dp" />
</FrameLayout>
Please can anyone tell me what's going wrong?
Finally i have managed to resolve the issue..the problem was that i was trying to place FAB inside fragment layout which obviously turned out to be not feasible. I moved it inside my activity xml layout as a child of CoordinatorLayout and now is actually a 'floating' action button...
Just move your FloatingButton above scroll view in xml layout
You need to position a FloatingActionButton within a CoordinatorLayout and use the CoordinatorLayout as the root of your Activity. (FloatingActionButton relies on features which the CoordinatorLayout enables) If your scrollview is a inside a fragment, this is still alright - so long as you assign an ID to the FloatingActionButton you can reference it from inside the fragment.
Replace your xml code with below code. You need to use Relative Layout or Coordinator Layout as root layout. And simply put floatig action button outside of framelayout.
<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">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="#+id/questionContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<com.rey.material.widget.TextView
android:id="#+id/surveyTitleTtv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="12dp"
android:textColor="#android:color/black"
android:textSize="20sp"
android:textStyle="bold" />
<com.rey.material.widget.TextView
android:id="#+id/test"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="12dp"
android:layout_marginLeft="12dp"
android:layout_marginRight="12dp"
android:textColor="#color/accentColor"
android:textSize="17dp"
android:textStyle="bold" />
</LinearLayout>
</ScrollView>
<com.rey.material.widget.FloatingActionButton
android:id="#+id/saveQuestionBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_gravity="bottom|right|end"
android:layout_marginBottom="16dp"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp"
android:text="ADD"
app:elevation="2dp" />