Реактивный шутник методом

просто добавьте кнопку FAB в RelativeLayout, как показано ниже, это может помочь

    <?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"
    android:id="@+id/mDrawerLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.design.widget.CoordinatorLayout
        android:id="@+id/coordinator"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

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

            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                android:background="@android:color/background_light"
                app:layout_scrollFlags="enterAlways|scroll" />

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

        <android.support.v4.widget.NestedScrollView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:layout_behavior="@string/appbar_scrolling_view_behavior">

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="This is sample Text" />
        </android.support.v4.widget.NestedScrollView>

       // try this
    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <android.support.design.widget.FloatingActionButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_margin="16dp"
            android:layout_alignParentBottom="true"
            android:layout_alignParentEnd="true"/>
    </RelativeLayout>

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

    <android.support.design.widget.NavigationView
        android:id="@+id/nav_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:background="@color/colorAccent"
        android:fitsSystemWindows="true"
        app:headerLayout="@layout/nav_header"
        app:menu="@menu/nav_menu" />


</android.support.v4.widget.DrawerLayout>
0
задан skyboyer 20 January 2019 в 11:58
поделиться

1 ответ

Проблема в том, что вы используете Math.sum(x,y) в качестве статической функции вместо ссылки на объект.

Вы можете изменить свою функцию на:

static sum(a, b){
  return a + b; 
}

Ссылки на объекты требуют, чтобы вы передавали переменные конструктору или динамически присваивали их через функцию.

let x, y;
class Math {
 //The constructor has optional parameters which default to 0. 
 constructor(first=0, second=0){
  this.x = first;
  this.y = second;
}

//Makes a sum with the variables passed through the constructor.
sum(){
 return x+y;
}

//sets the x value
changeX(num){ x = num; }

//returns the x value
getX(){ return x; }

//This function saves it to the object beforehand so you may retrieve it later. 
sumSaved(first, second){
  this.x = first;
  this.y = second;
return x + y;
} 

//Assigned through the constructor.
let foo = new Math(first:1,second:2);
foo.sum(); //returns 3 because 1+2=3
foo.changeX(2);
foo.sum(); //returns 4 because 2+2=4

//Assigned through a function.
let bar = new Math();
bar.sumSaved(4,6); //returns 10 and overwrites variables.
bar.getX(); //returns 4, because you saved it earlier. 

См. здесь для получения информации о статических функциях.

См. здесь , когда вам следует использовать статические функции.

Также, для информации об экспорте по умолчанию, читайте здесь .

0
ответ дан sheepiiHD 20 January 2019 в 11:58
поделиться
Другие вопросы по тегам:

Похожие вопросы: