0

I have one Floating Action Button in a screen. This button will help to add some items. I am able to add this button in the screen but it is not moving across the screen.

I know there is flaw in the layout. I have added my layout code here. Can someone please tell me where is the problem:

<?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"
    android:id="@+id/clayout">
<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/bg5"
    android:orientation="vertical"
    tools:context="com.app.dhinchakwale.ui.CheckOutActivity">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/aluminum"
        android:orientation="vertical">

        <ListView
            android:id="@+id/checkout_list"
            android:layout_width="fill_parent"
            android:layout_height="match_parent"
            android:layout_above="@+id/bottombar"
            android:layout_marginBottom="10dp"
            android:layout_marginLeft="10dp"
            android:layout_marginRight="10dp"
            android:layout_marginTop="10dp"
            android:layout_weight="1"
            android:background="@drawable/row_bg"
            android:cacheColorHint="#00000000"
            android:choiceMode="singleChoice"
            android:divider="@color/base"
            android:dividerHeight="1sp"
            android:focusable="true"
            android:textSize="16sp"
            android:typeface="serif"
            android:visibility="visible" />

        <LinearLayout
            android:id="@+id/bottom_placed_white"
            android:layout_width="fill_parent"
            android:layout_height="140dp"
            android:layout_alignParentBottom="true"
            android:background="#ffffff"
            android:orientation="vertical">

            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="10dp"
                android:layout_marginRight="10dp">

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentLeft="true"
                    android:layout_marginLeft="20dp"
                    android:singleLine="true"
                    android:text="Total: "
                    android:textColor="@color/done_text_color"
                    android:textSize="16sp"
                    android:typeface="sans" />

                <TextView
                    android:id="@+id/total_amt"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentRight="true"
                    android:layout_marginLeft="20dp"
                    android:singleLine="true"
                    android:textColor="@color/black"
                    android:text="Rs 100000"
                    android:textSize="16sp"
                    android:typeface="sans" />
            </RelativeLayout>

            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="5dp"
                android:layout_marginRight="10dp">

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentLeft="true"
                    android:layout_marginLeft="20dp"
                    android:singleLine="true"
                    android:text="Service Tax(14.5%)"
                    android:textColor="@color/done_text_color"
                    android:textSize="16sp"
                    android:typeface="sans" />

                <TextView
                    android:id="@+id/vat_amt"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentRight="true"
                    android:layout_marginLeft="20dp"
                    android:singleLine="true"
                    android:textColor="@color/black"
                    android:text="Rs 100000"
                    android:textSize="16sp"
                    android:typeface="sans" />
            </RelativeLayout>

            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="5dp"
                android:layout_marginRight="10dp">

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentLeft="true"
                    android:layout_marginLeft="20dp"
                    android:singleLine="true"
                    android:text="You Pay: "
                    android:textColor="@color/done_text_color"
                    android:textSize="18sp"
                    android:typeface="sans" />

                <TextView
                    android:id="@+id/total_chkout_amt"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentRight="true"
                    android:layout_marginLeft="20dp"
                    android:singleLine="true"
                    android:textColor="@color/black"
                    android:text="Rs 100000"
                    android:textSize="22sp"
                    android:textStyle="bold"
                    android:typeface="sans" />
            </RelativeLayout>

            <LinearLayout
                android:id="@+id/bottombar"
                android:layout_width="fill_parent"
                android:layout_height="50dp"
                android:background="#25383C"
                android:orientation="horizontal"
                android:weightSum="2">

                <LinearLayout
                    android:id="@+id/sort_ll"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="10dp"
                    android:layout_weight="1"
                    android:clickable="true"
                    android:gravity="center_horizontal"
                    android:orientation="horizontal">

                    <ImageView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center_vertical"
                        android:src="@drawable/phone" />

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center_vertical"
                        android:layout_marginLeft="5dp"
                        android:text="Take Advice"
                        android:textColor="@android:color/white"
                        android:textSize="16sp" />
                </LinearLayout>

                <View
                    android:layout_width="1dp"
                    android:layout_height="50dp"
                    android:background="@android:color/white" />

                <LinearLayout
                    android:id="@+id/filter_ll"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="10dp"
                    android:layout_weight="1"
                    android:gravity="center_horizontal"
                    android:orientation="horizontal">

                    <ImageView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center_vertical"
                        android:src="@drawable/checkout" />

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center_vertical"
                        android:layout_marginLeft="5dp"
                        android:text="Checkout"
                        android:textColor="@android:color/white"
                        android:textSize="16sp" />
                </LinearLayout>
            </LinearLayout>
        </LinearLayout>
    </LinearLayout>


    <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"
        app:rippleColor="@color/blue"
        app:backgroundTint="@color/primary"
        android:src="@android:drawable/ic_input_add" />


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

In the Activity I have added the below code:

FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
        mCoordinatorLayout = (CoordinatorLayout) findViewById(R.id.clayout);

        fab.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                Intent intent = new Intent();
                intent.setClass(CheckOutActivity.this, HomeScreen.class);
//                callIntent.setData(Uri.parse("tel:"+strPhone));
                startActivity(intent);
                finishAffinity();
                Snackbar.make(mCoordinatorLayout, "", Snackbar.LENGTH_LONG)
                        .setAction("Action", null).show();
            }
        });

Please help me on this.

Thanks, Arindam.

Arindam Mukherjee
  • 2,255
  • 11
  • 48
  • 83
  • Please follow the question trails http://stackoverflow.com/questions/24459352/how-can-i-add-the-new-floating-action-button-between-two-widgets-layouts?rq=1 – Abhishek Feb 11 '16 at 10:58
  • This is only talking about how to add the button. But I am having issue to move the button. I am already checked that thread.. – Arindam Mukherjee Feb 11 '16 at 11:07

0 Answers0