xml - android: Which practice is better for using CoordinatorLayout -


i new material design aspect of android. so, please bear me. tried implementing fab home activity, , implemented snackbar. naturally, came above fab. researched on coordinatorlayout , what's bothering me 1 better practice using coordinatorlayout?

for example, here's xml of activity.

<relativelayout     android:layout_width="match_parent"     android:layout_height="match_parent"     tools:context=".mainactivity">          <android.support.v7.widget.toolbar             android:id="@+id/toolbar"             android:layout_width="match_parent"             android:layout_height="wrap_content"             android:background="@color/primary_color"></android.support.v7.widget.toolbar>           <android.support.design.widget.floatingactionbutton             android:id="@+id/searchfab"             android:layout_width="wrap_content"             android:layout_height="wrap_content"             android:layout_alignparentright="true"             android:layout_alignparentbottom="true"             android:layout_marginbottom="20dp"             android:layout_marginright="20dp"             android:src="@drawable/ic_add_black_24dp"             app:fabsize="normal">          </android.support.design.widget.floatingactionbutton>  </relativelayout> 

i watched other people adding coordinatorlayout this.

<relativelayout     android:layout_width="match_parent"     android:layout_height="match_parent"     tools:context=".mainactivity">       <android.support.v7.widget.toolbar         android:id="@+id/toolbar"         android:layout_width="match_parent"         android:layout_height="wrap_content"         android:background="@color/primary_color"></android.support.v7.widget.toolbar>      <android.support.design.widget.coordinatorlayout         android:layout_width="match_parent"         android:layout_height="match_parent">          <android.support.design.widget.floatingactionbutton             android:id="@+id/searchfab"             android:layout_width="wrap_content"             android:layout_height="wrap_content"             android:layout_alignparentbottom="true"             android:layout_alignparentright="true"             android:layout_marginbottom="20dp"             android:layout_marginright="20dp"             android:src="@drawable/ic_add_black_24dp"             app:fabsize="normal">          </android.support.design.widget.floatingactionbutton>      </android.support.design.widget.coordinatorlayout> </relativelayout> 

my question is, can use <android.support.design.widget.coordinatorlayout> root of elements. bypassing or removing <relativelayout>.

so xml becomes this.

    <android.support.design.widget.coordinatorlayout         android:layout_width="match_parent"         android:layout_height="match_parent"         tools:context=".mainactivity">          <android.support.v7.widget.toolbar         android:id="@+id/toolbar"         android:layout_width="match_parent"         android:layout_height="wrap_content"         android:background="@color/primary_color">          <android.support.design.widget.floatingactionbutton             android:id="@+id/searchfab"             android:layout_width="wrap_content"             android:layout_height="wrap_content"             android:layout_alignparentbottom="true"             android:layout_alignparentright="true"             android:layout_marginbottom="20dp"             android:layout_marginright="20dp"             android:src="@drawable/ic_add_black_24dp"             app:fabsize="normal">          </android.support.design.widget.floatingactionbutton>      </android.support.design.widget.coordinatorlayout> 

and <relativelayout> removed. instead of using </android.support.design.widget.coordinatorlayout> fab, use whole activity. coordinatorlayout focuses on making child views work coordinated, isn't better if elements work in coordination 1 another? advantages , disadvantages of doing either ways?

coordinatorlayout relatively new , resolves lot of issues floatingactionbutton , navdrawer. if must have fab or navdrawer recommend using coordinatorlayout top level layout on (your last code snippet) , inside can have relativelayout or linearlayout more refinement.


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -