浮动操作按钮未在屏幕中移动

时间:2016-02-11 10:51:53

标签: android floating-action-button

我在屏幕上有一个浮动操作按钮。此按钮将有助于添加一些项目。我可以在屏幕上添加此按钮,但它不会在屏幕上移动。

我知道布局有缺陷。我在这里添加了我的布局代码。有人可以告诉我问题出在哪里:

<?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>

在活动中,我添加了以下代码:

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();
            }
        });

请帮我解决这个问题。

谢谢, 阿瑞丹姆。

0 个答案:

没有答案
相关问题