Devesh Agrawal
Devesh Agrawal

Reputation: 9212

button not displaying in bottom of activity - android

This is my layout file.

<?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/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.design.widget.CoordinatorLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:id="@+id/coordinatorLayout"
        android:orientation="vertical">

        <android.support.design.widget.AppBarLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

            <include
                android:id="@+id/toolbar"
                layout="@layout/toolbar"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                app:layout_scrollFlags="scroll|enterAlways"
                android:layout_alignParentTop="true"/>


            <android.support.design.widget.TabLayout
                android:id="@+id/tab_layout"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@+id/toolbar"
                android:background="@color/primary"
                android:elevation="6dp"
                android:minHeight="?attr/actionBarSize"
                app:tabIndicatorColor="@android:color/white"
                app:tabIndicatorHeight="4dp"
                android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"/>

        </android.support.design.widget.AppBarLayout>

        <android.support.v4.view.ViewPager
            android:id="@+id/pager"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/tab_layout"
            android:layout_above="@+id/floating_button"
            android:background="@color/windowBackground"
            android:paddingLeft="30dp"
            app:layout_behavior="@string/appbar_scrolling_view_behavior"/>

        <Button android:id="@+id/floating_button"
            android:layout_width="match_parent"
            android:layout_alignParentBottom="true"
            android:layout_height="wrap_content"
            android:text="Go to Shopping Cart"
            android:theme="@style/MyButton"/>


    </android.support.design.widget.CoordinatorLayout>

    <fragment
        android:id="@+id/fragment_navigation_drawer"
        android:name="com.wokoshop.sony.fragment.FragmentDrawer"
        android:layout_width="@dimen/nav_drawer_width"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        app:layout="@layout/fragment_navigation_drawer"
        tools:layout="@layout/fragment_navigation_drawer" />

</android.support.v4.widget.DrawerLayout>

I am trying to display a button bottom of the activity. But it is not displaying at all.

Can someone help me what i am missing?

Upvotes: 1

Views: 353

Answers (1)

I think you have several minor issues that causes your problem.

1) You're trying to use the cooridnator layout as a relative layout, so the buttons alignParentBottom won't have any effect.

2) Orientation on the coordinator layout is a linear layout property and would have no effect.

3) The coordinator layout or anything within it doesn't use the full parent, all of them are only wrap_parent.

From reading your layout I think you'd want something like this:

   <android.support.design.widget.CoordinatorLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <android.support.design.widget.AppBarLayout
                android:id="@+id/appBarlayout"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

                <!-- Whatever views you want here, your tablayout etc-->

            </android.support.design.widget.AppBarLayout>

            <android.support.v4.view.ViewPager
                android:layout_below="@+id/appBarlayout"
                android:layout_above="@+id/button"
                android:layout_width="match_parent"
                android:layout_height="match_parent">

            </android.support.v4.view.ViewPager>

            <Button
                android:id="@+id/button"
                android:text="Hey"
                android:layout_alignParentBottom="true"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" />

        </RelativeLayout>

    </android.support.design.widget.CoordinatorLayout>

Upvotes: 3

Related Questions