FloatingActionButton与Snackbar和透明导航栏

时间:2015-12-07 13:24:10

标签: android material-design floating-action-button android-coordinatorlayout android-snackbar

我的<item name="android:windowTranslucentNavigation">true</item>中有styles.xml

由于透明导航栏,我给出了浮动操作按钮边距。

我有一个问题,我的小吃店位于透明导航栏下方。我通过给小吃店添加一个填充物来解决这个问题,但现在我的小吃吧和我的浮动动作按钮之间有很大的空间。我尝试为我的浮动操作按钮创建自定义行为,但当快餐栏被解除或显示时,导航栏的自定义边距和小吃店的填充导致错误的高度。

这是我在android.support.design.widget.CoordinatorLayout内的具有属性android:fitsSystemWindows="true"

的浮动操作按钮
<android.support.design.widget.FloatingActionButton
        android:id="@+id/myFAB"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentEnd="true"
        android:layout_alignParentRight="true"
        android:layout_gravity="bottom|right|end"
        android:layout_marginEnd="10dp"
        android:layout_marginRight="10dp"
        app:borderWidth="0dp"
        app:elevation="12dp"
        app:layout_behavior="...ScrollAwareFABBehavior"
        app:rippleColor="@color/md_indigo_700" />

我还没有找到一个解决方案,可以在FloatingActionButton上方SnackBarNavigationBar对齐,而不会破坏behavior

我的CoordinatorLayout位于一个片段内。这是活动布局:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/content_frame"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true" />

片段布局:

<?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:wheel="http://schemas.android.com/apk/res-auto"
    android:id="@+id/main_content"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true">

    <include layout="@layout/fragment_toolbar" />

    <com.pnikosis.materialishprogress.ProgressWheel
        android:id="@+id/progress_wheel"
        android:layout_width="80dp"
        android:layout_height="80dp"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:layout_gravity="center"
        android:visibility="gone"
        wheel:matProg_barColor="#5588FF"
        wheel:matProg_progressIndeterminate="true" />

    <android.support.v7.widget.RecyclerView xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/recyclerView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:clipToPadding="false"
        android:paddingBottom="@dimen/navigation_bar_bottom_padding"
        app:layout_behavior="@string/appbar_scrolling_view_behavior" />

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/myFAB"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentEnd="true"
        android:layout_alignParentRight="true"
        android:layout_gravity="bottom|right|end"
        android:layout_marginEnd="10dp"
        android:layout_marginRight="10dp"
        app:borderWidth="0dp"
        app:elevation="12dp"
        app:layout_behavior="...ScrollAwareFABBehavior"
        app:rippleColor="@color/md_indigo_700" />

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

1 个答案:

答案 0 :(得分:0)

我认为这样做。检查一下,如果不能正常工作,请分享您的零食店代码。

import java.util.ArrayList;
public class Go {
    public static void main(String[] args) {
        // running below creates an ArrayList<Ansat> that is inside KlasseObject
        Data klasseObject = new Data();

        // creates one Ansat(Hey,123) and add it to list
        klasseObject.setData("Hey", 123);

        // creates one Ansat(Raf,555) and add it to list
        klasseObject.setData("Raf", 555);

        // creates one Ansat(X-men,999) and add it to list
        klasseObject.setData("X-men", 999);

        //as many classes as you want, it would add them all to the list
        //of klasseObject 

        // now that we set three Ansats, we will retrieve the list and print
        // them all
        for (Ansat s : klasseObject.getAnsatList())
            System.out.println(s.toString());
    }
}

class Ansat {
    public String navn;
    public int alder;

    //remove the array list from constructor, not needed
    public Ansat(String navn, int alder) {
        this.navn = navn;
        this.alder = alder;
    }

    public int getAlder() {
        return alder;
    }

    public void setAlder(int alder) {
        this.alder = alder;
    }

    public String getNavn() {
        return navn;
    }

    public void setNavn(String navn) {
        this.navn = navn;
    }

    //overrided toString method to pretty-print Ansat object
    public String toString() {
        return navn + " , " + alder;
    }
}

class Data {
    private ArrayList<Ansat> ansat;

    // added the constructor for Data to initialize Data with empty list
    public Data() {
        ansat = new ArrayList<Ansat>();
    }

    //replaced infoListe to setData and added args to it so you can 
    //pass them from main method
    public void setData(String name, int age) {
        // every time setData is called a new Ansat is added to list
        Ansat a = new Ansat(name, age);
        ansat.add(a);
    }

    public ArrayList<Ansat> getAnsatList() {
        return ansat;
    }
}