How place floatingactionbutton on end of layout - android-layout

I wanna place my floatingactionbutton on the end from the bottom of a relativelayout. How i do this as best and most practical?
Here's a screenshot, how it should look:

This functionality only works when your parent layout is a coordinator layout.This can be achieved using the app:layout_anchor="" and the app:layout_anchorGravity=""
Some thing like this:
<?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/com.example.myapp"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#ffffff"
>
<android.support.design.widget.AppBarLayout android:layout_height="wrap_content"
android:layout_width="match_parent"
android:id="#+id/appBar"
>
<!-- Put your content that is supposed to be in the appbar here -->
</android.support.design.widget.AppBarLayout>
<android.support.design.widget.FloatingActionButton
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:src="#drawable/your_drawable_resource_file"
app:borderWidth="0dp"
app:fabSize="normal"
app:layout_anchor="#id/appBar"
app:layout_anchorGravity="left|bottom|start"/>
</android.support.design.widget.CoordinatorLayout>
Hope this was helpful.

If your parent layout is Relative Layout.
Just use
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
<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:clickable="true"
android:orientation="vertical">
<android.support.design.widget.FloatingActionButton
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:id="#+id/myFAB"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_plus_sign"
app:elevation="4dp"
/>
</RelativeLayout>

Related

Linear Layout and children not visible

Hi sorry I am having difficulty in getting my layout to been seen when I run the application
I don't see anything when I run my application
here is my XML code
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<LinearLayout
android:layout_width="409dp"
android:layout_height="729dp"
android:layout_marginStart="1dp"
android:layout_marginLeft="1dp"
android:layout_marginTop="1dp"
android:layout_marginEnd="1dp"
android:layout_marginRight="1dp"
android:layout_marginBottom="1dp"
android:orientation="vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<TextView
android:id="#+id/edtName"
android:layout_width="match_parent"
android:layout_height="44dp"
android:text="Name" />
<ScrollView
android:id="#+id/scrlText"
android:layout_width="match_parent"
android:fillViewport="true"
android:isScrollContainer="true"
android:layout_height="638dp">
<LinearLayout
android:id="#+id/lltext"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" />
</ScrollView>
<LinearLayout
android:id="#+id/hllsend"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<EditText
android:id="#+id/edtInput"
android:layout_width="159dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
android:inputType="textPersonName" />
<Button
android:id="#+id/btnSend"
android:layout_width="10dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Button" />
</LinearLayout>
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
How do I make my items visible when running the application?
In your simple layout code, there are many problems. For example:
1.
android:layout_width="409dp"
android:layout_height="729dp"
such android screen size is hard to get. And in Android layout principal, you'd better use relative layout rather than such hard code size. Here you can replace it with match_parent or wrap_content.
In the same way.
android:layout_height="638dp"
totally over screen height ,make no space for hllsend to show.
I suggest you learn some android layout principal before write android app.
It's not a good practice to add LinearLayout in ConstraintLayout and I think it's the issue with your code you just need to make you LinearLayout as a parent and remove your ConstraintLayout.
NOTE: please do necessary adjustment.
Please check quick example for your code I didn't run this.
<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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<LinearLayout
android:layout_width="409dp"
android:layout_height="729dp"
android:layout_marginStart="1dp"
android:layout_marginLeft="1dp"
android:layout_marginTop="1dp"
android:layout_marginEnd="1dp"
android:layout_marginRight="1dp"
android:layout_marginBottom="1dp"
android:orientation="vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<TextView
android:id="#+id/edtName"
android:layout_width="match_parent"
android:layout_height="44dp"
android:text="Name" />
<ScrollView
android:id="#+id/scrlText"
android:layout_width="match_parent"
android:fillViewport="true"
android:isScrollContainer="true"
android:layout_height="638dp">
<LinearLayout
android:id="#+id/lltext"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" />
</ScrollView>
<LinearLayout
android:id="#+id/hllsend"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<EditText
android:id="#+id/edtInput"
android:layout_width="159dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
android:inputType="textPersonName" />
<Button
android:id="#+id/btnSend"
android:layout_width="10dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Button" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
put all your xml codes in LinearLayout and remove ConstraintLayout . thats may helps.

Persistent bottom sheet peek covering last RecyclerView item

I have implemented a persistent bottom sheet in my layout - one that cannot be completely hidden but always peeks from the bottom.
But it covers the last RecyclerView item.
How can I set the layout in such a way the peek doesn't hide the last item?
Screenshot:-
<?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:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v4.widget.NestedScrollView
android:id="#+id/nestedScrollView"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="#+id/recylerView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_weight="1" />
</RelativeLayout>
</android.support.v4.widget.NestedScrollView>
<!-- Buttom Sheet -->
<android.support.v7.widget.LinearLayoutCompat
android:id="#+id/bottom_sheet"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#android:color/white"
android:orientation="vertical"
app:behavior_hideable="true"
app:behavior_peekHeight="56dp"
app:layout_behavior="android.support.design.widget.BottomSheetBehavior">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="56dp"
android:layout_gravity="center_vertical"
android:background="#android:color/holo_green_dark"
android:orientation="horizontal"
android:padding="10dp"
android:weightSum="3">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_weight="2"
android:text="Submit Report"/>
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="right"
android:text="8/10"/>
</LinearLayout>
<!-- Other things to add -->
</android.support.v7.widget.LinearLayoutCompat>
</android.support.design.widget.CoordinatorLayout>
</FrameLayout>
This is silly. I knew the solution by myself right after posting the problem. :)
Just needed to add android:paddingBottom attribute to the RecyclerView.
<android.support.v7.widget.RecyclerView
android:id="#+id/studentListView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="56dp"/>

Coordination Layout Don't Work With Tab Layout

Good day can you help me correct this one?
In my activity_main.xml, I used Coordination Layout So that my Appbar will work.
<android.support.v4.widget.DrawerLayout
android:id="#+id/drawer_layout"
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:fitsSystemWindows="true"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context="com.eccp.projects.ecosavers.ecosavers.activities.eco_detailed_information">
<!--COORDINATOR LAYOUT-->
<android.support.design.widget.CoordinatorLayout
android:id="#+id/coordinator_layout"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:background="#ffffff">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/ThemeOverlay.AppCompat.Dark">
<include
android:id="#+id/toolbar"
layout="#layout/tool_bar"
/>
<android.support.design.widget.TabLayout
android:id="#+id/tablayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:elevation="4dp"
app:tabMode="fixed"
app:tabGravity="fill"/>
<android.support.v4.view.ViewPager
android:id="#+id/pager"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_weight="1"
android:background="#ffffff"/>
</android.support.design.widget.AppBarLayout>
</android.support.design.widget.CoordinatorLayout>
<android.support.design.widget.NavigationView
android:id="#+id/navigation_view"
android:layout_height="match_parent"
android:layout_width="wrap_content"
android:layout_gravity="start"
app:headerLayout="#layout/header"
app:menu="#menu/drawer"/>
And In my First Tab my - Organizations feeds don't work, it stuck and will not me allow to slide up to show up the feeds. But sometimes it will work sliding up but, there is an overlapping of layout. I just include my cardview_items.xml as an overview on how it looks like.
<RelativeLayout
android:orientation="vertical"
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:scrollbarAlwaysDrawVerticalTrack="true"
android:fitsSystemWindows="true"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context="com.eccp.projects.ecosavers.ecosavers.activities.eco_detailed_information">
<!--COORDINATOR LAYOUT-->
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fillViewport="true"
android:layout_gravity="fill_vertical"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:layout_marginTop="1dp">
<!--Dummy Value 1-->
<include
android:id="#+id/card_item"
layout="#layout/eco_events_cardview" />
<include
android:id="#+id/card_item"
layout="#layout/eco_events_cardview" />
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
I really need your help. I'm stuck with this one.
Thank you in advance.
It should be fairly easy to fix:
Remove ViewPager from AppBarLayout
Add ViewPager as a sibling to a AppBarLayout and add for it app:layout_behavior="#string/appbar_scrolling_view_behavior" and set layout_width & layout_height to match_parent
So your layout should look like afterwards:
<android.support.design.widget.CoordinatorLayout
....>
<android.support.design.widget.AppBarLayout
.....>
<include
android:id="#+id/toolbar"
layout="#layout/tool_bar"/>
<android.support.design.widget.TabLayout
.../>
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
.....
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior" />
</android.support.design.widget.CoordinatorLayout>
I hope, it helps.

toolbar overlaps my fragments (multi pane)

I am trying to have two fragments shown at the same time on a horizontal orientation of my activity alongwith a toolbar. But the toolbar overlaps the fragments. I'm not sure where to place it. Btw, the toolbar comes with a navigation view, so it's in a drawerlayout.
Here's my xml.
<android.support.v4.widget.DrawerLayout 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_drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar">
<LinearLayout
android:id="#+id/main_content_fragments"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<android.support.v7.widget.Toolbar
android:id="#+id/main_app_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/colorPrimary"
app:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar" />
<fragment
android:id="#+id/activity_fragment_main_event_list"
class="com.torneyo.torneyoadmin.fragments.EventListFragment"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1" />
<fragment
android:id="#+id/activity_fragment_main_event_detail"
class="com.torneyo.torneyoadmin.fragments.EventDetailFragment"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="3"
android:background="?android:attr/detailsElementBackground" />
</LinearLayout>
<android.support.design.widget.NavigationView
android:id="#+id/main_drawer"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
app:headerLayout="#layout/drawer_header"
app:itemIconTint="#color/colorAccent"
app:itemTextColor="#color/colorTextSecondary"
app:menu="#menu/menu_drawer" />
</android.support.v4.widget.DrawerLayout>
Thoughts? I need to have the fragments show up. I'm not sure I'm using the layouts correctly.
Thanks!
Hello I see your layout file. I think the problem in it. It should inside the relative layout. kindly see the below modified layout version. Apply it let me know if you have any question in it.
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout 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_drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.Toolbar
android:id="#+id/main_app_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:background="#color/colorPrimary"
app:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar" />
<LinearLayout
android:id="#+id/main_content_fragments"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/main_app_toolbar"
android:orientation="horizontal">
<fragment
android:id="#+id/activity_fragment_main_event_list"
class="com.torneyo.torneyoadmin.fragments.EventListFragment"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1" />
<fragment
android:id="#+id/activity_fragment_main_event_detail"
class="com.torneyo.torneyoadmin.fragments.EventDetailFragment"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="3"
android:background="?android:attr/detailsElementBackground" />
</LinearLayout>
</RelativeLayout>
<android.support.design.widget.NavigationView
android:id="#+id/main_drawer"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
app:headerLayout="#layout/drawer_header"
app:itemIconTint="#color/colorAccent"
app:itemTextColor="#color/colorTextSecondary"
app:menu="#menu/menu_drawer" />
</android.support.v4.widget.DrawerLayout>

How to put both customview and linearlayout in same xml file

my problem is ,i am using one custom-view in my XML file ,that same XML file also contain other component such as text-view ,image-buttons,
that custom-view contains the images ,that i want on background
but it is blocking my whole layout (other components)
and i can see only custom-view
following is my code
<FrameLayout
android:id="#+id/framelayout"
android:layout_height="fill_parent"
android:layout_width="fill_parent">
<com.abc.android.image
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/imageview">
</com.abc.android.image>
<LinearLayout
android:id="#+id/linlayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/small1"
android:orientation="vertical">
All text view, ImageButtons
</LinearLayout>
</FrameLayout>
can anyone please tell how to use custom-view at background and other components on a foreground. means components should display over the Custom-view.
Thanx in advance.
Please check the following code. I have added just two UI widgets i.e a TextView and a Button. You can add more according to you need.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/linearlayout01" android:layout_height="fill_parent"
android:layout_width="fill_parent">
<FrameLayout android:id="#+id/framelayout01"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:orientation="vertical">
<ImageView android:layout_width="fill_parent"
android:layout_height="fill_parent" android:id="#+id/imageview01"
android:background="#drawable/pic">
</ImageView>
<LinearLayout android:id="#+id/linearlayout02"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:orientation="vertical">
<TextView android:text="Text View" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:textSize="40dip"
android:textStyle="bold" android:layout_gravity="center"
android:layout_marginTop="50dip" android:textColor="#FF0000" />
<Button android:text="Button" android:layout_width="fill_parent"
android:layout_height="80dip" android:gravity="center"
android:textSize="40dip" android:textStyle="bold"
android:layout_marginTop="50dip" />
</LinearLayout>
</FrameLayout>

Resources