Floating Button in Linear Layout (FBLL)


FBLL:   SOLD       




When a layout design starts from scratch, I certainly won't use Linear layout if it contains components with irregular layouts. But who would have thought that if an application we create develops and requires a floating action button to be placed there.

The bad thing is, the activity layout uses Linear Layout as its parent, it would be very messy if I had to change it to relative layout or constraint layout, hmm it would definitely mess up the arrangement of the components that are already there.

Well, after I did the Google Fu trick, it turns out there is still a solution to overcome this, namely by using Frame Layout, so the implementation will be like this.

<?xml version="1.0" encoding="utf-8"?>
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
   android:layout_width="fill_parent"
   android:layout_height="fill_parent"
   android:orientation="vertical"
   android:background="@drawable/background_serious" >

      <include layout="@layout/toolbar"/>
  <FrameLayout
         android:layout_width="match_parent"
         android:layout_height="match_parent">

          <ListView android:id="@id/android:list"
              android:layout_width="fill_parent"
              android:layout_height="wrap_content"
              android:cacheColorHint="#00000000">
          </ListView>

     <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_done" />

  </FrameLayout>
</LinearLayout>

Okay, that's about it, if you have a different shape, feel free to adjust it yourself, good luck!


Post a Comment

Previous Next

نموذج الاتصال