android - Coordinator Layout and Relative Layout issue -


when create blank activity in android studio, given 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.example.mainactivity">      <android.support.design.widget.appbarlayout         android:layout_width="match_parent"         android:layout_height="wrap_content"         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/content_main"  />      <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="@android:drawable/ic_dialog_email" />  </android.support.design.widget.coordinatorlayout> 

and relative layout (@layout/content_main) goes out of screen:

http://i.imgur.com/8tx0zis.png

if set button in relative layout, layout_alignparentbottom button go out of screen. (it doesn't happen time, have no idea why)

@layout/content_main

<?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:layout_width="match_parent"     android:layout_height="match_parent"     app:layout_behavior="@string/appbar_scrolling_view_behavior"     tools:context="com.example.mainactivity"     tools:showin="@layout/activity_main">      <button         android:id="@+id/button"         android:layout_alignparentbottom="true"         android:layout_width="match_parent"         android:layout_height="70dp"         android:background="@color/green"           android:textcolor="@color/white"         android:text="text"         android:focusable = "true"         android:focusableintouchmode = "true"         />  </relativelayout> 

adding padding bottom relative layout won't work. (as it'll work when button off screen)

i need button @ bottom of screen always. can tell me how achieve this?

like this:

http://i.imgur.com/0fdavx2.png

enter image description here

try following code, keep button @ end without going out of view:

<?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.example.android.myapplication.mainactivity">      <android.support.design.widget.appbarlayout         android:layout_width="match_parent"         android:layout_height="wrap_content"         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>       <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="@android:drawable/ic_dialog_email" />      <button         android:id="@+id/btn"         android:layout_width="match_parent"         android:layout_height="wrap_content"         android:layout_gravity="bottom" />  </android.support.design.widget.coordinatorlayout> 

and relative layout (@layout/content_main) goes out of screen:

edit: think that's because you've set them match_parent.try 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-auto"     xmlns:tools="http://schemas.android.com/tools"     android:layout_width="match_parent"     android:layout_height="match_parent"     android:fitssystemwindows="true"     tools:context="com.example.mainactivity">      <android.support.design.widget.appbarlayout         android:id="@+id/app_bar"         android:layout_width="match_parent"         android:layout_height="wrap_content"         android:background="@android:color/transparent"         android:fitssystemwindows="true"         android:theme="@style/themeoverlay.appcompat.dark.actionbar">          <android.support.design.widget.collapsingtoolbarlayout             android:id="@+id/collapsing_toolbar"             android:layout_width="match_parent"             android:layout_height="300dp"             android:background="@color/colorprimary"             android:fitssystemwindows="true"             app:contentscrim="?attr/colorprimary"             app:layout_scrollflags="scroll|exituntilcollapsed">              <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.collapsingtoolbarlayout>      </android.support.design.widget.appbarlayout>      <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="@android:drawable/ic_dialog_email" />      <relativelayout         android:layout_width="match_parent"         android:layout_height="wrap_content">          <button             android:id="@+id/button"             android:layout_width="match_parent"             android:layout_height="70dp"             android:layout_alignparentbottom="true"             android:background="@color/coloraccent"             android:focusable="true"             android:focusableintouchmode="true"             android:text="text"             android:textcolor="@android:color/white" />      </relativelayout>  </android.support.design.widget.coordinatorlayout> 

Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -