Java 浮动操作按钮菜单不随标题滚动

Java 浮动操作按钮菜单不随标题滚动,java,android,material-design,floating-action-button,Java,Android,Material Design,Floating Action Button,我目前正在编写一个小应用程序,我试图整合谷歌的“材料设计” 我在我的应用程序中使用github的浮动操作菜单按钮库,我有些担心 与单个按钮不同,菜单生成更大的视图。我把菜单放在工厂的标题下。但代码似乎并不好 我希望在标题下正确显示菜单fab(我使用折叠工具栏布局)。菜单跟随滚动条。但我被困在这里了 我的问题是如何将菜单fab放在标题和卡片视图之间,以及如何使用折叠工具栏滚动fab菜单 先谢谢你 我的布局: <?xml version="1.0" encoding="utf-8"?&

我目前正在编写一个小应用程序,我试图整合谷歌的“材料设计”

我在我的应用程序中使用github的浮动操作菜单按钮库,我有些担心

与单个按钮不同,菜单生成更大的视图。我把菜单放在工厂的标题下。但代码似乎并不好

我希望在标题下正确显示菜单fab(我使用折叠工具栏布局)。菜单跟随滚动条。但我被困在这里了

我的问题是如何将菜单fab放在标题和卡片视图之间,以及如何使用折叠工具栏滚动fab菜单

先谢谢你

我的布局:

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

<android.support.design.widget.CoordinatorLayout
 android:id="@+id/coordinatorlayout"
 android:layout_width="fill_parent"
 android:layout_height="match_parent"
 app:expandedTitleMarginStart="70dp">

    <android.support.design.widget.AppBarLayout
     android:theme="@style/AppTheme.AppBarOverlay"
     android:layout_width="fill_parent"
     android:id="@+id/appbarlayout"
     android:layout_height="230dp">

        <android.support.design.widget.CollapsingToolbarLayout
         android:id="@+id/CollapsingToolbarLayout1"
         android:layout_width="match_parent"
         android:layout_height="match_parent"
         app:layout_scrollFlags="scroll|exitUntilCollapsed">

            <ImageView
              android:id="@+id/image"
              android:layout_width="match_parent"
              android:layout_height="match_parent"
              android:scaleType="centerCrop"
              android:src="@drawable/console_font"/>

            <android.support.v7.widget.Toolbar
             android:id="@+id/toolbar"
             android:title="test"
             android:layout_width="match_parent"
             android:layout_height="?attr/actionBarSize"
             app:popupTheme="@style/AppTheme.PopupOverlay"
             android:clickable="true"
             app:layout_collapseMode="pin"
             android:minHeight="?attr/actionBarSize"/>

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

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

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

        <LinearLayout
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:orientation="vertical">

                <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
                  android:layout_width="fill_parent"
                  android:layout_height="wrap_content"
                  android:orientation="vertical" >

                    <LinearLayout
                      android:layout_width="fill_parent"
                      android:layout_height="match_parent"
                      android:layout_gravity="top"
                      android:layout_weight=".1" >

                        <android.support.v7.widget.CardView
                         xmlns:card_view="http://schemas.android.com/apk/res-auto"
                         android:id="@+id/card_view"
                         android:layout_width="match_parent"
                         android:layout_height="match_parent"
                         android:layout_marginTop="10dp"
                         android:layout_marginBottom="10dp"
                         android:layout_marginLeft="10dp"
                         android:layout_marginRight="10dp">

                            <LinearLayout
                              android:layout_alignParentBottom="true"
                              android:id="@+id/fragmentContainer"
                              android:layout_width="fill_parent"
                              android:layout_height="wrap_content"
                              android:orientation="vertical"
                              android:layout_marginLeft="10dp">

                                <TextView 
                                  android:textColor="@android:color/holo_blue_light"
                                  android:layout_marginTop="10dp"
                                  android:layout_width="wrap_content"
                                  android:layout_height="wrap_content"
                                  android:textAppearance="?android:attr/textAppearanceLarge"
                                  android:text="Console"
                                  android:id="@+id/textView5" />

                                <Spinner
                                    android:layout_marginTop="10dp"
                                    android:layout_width="match_parent"
                                    android:layout_height="wrap_content"
                                    android:id="@+id/spinner"
                                    android:layout_gravity="center_horizontal" />

                                <View style="@style/Divider"/>

                                <TextView 
                                    android:textColor="@android:color/holo_blue_light"
                                    android:layout_marginTop="20dp"
                                    android:layout_width="wrap_content"
                                    android:layout_height="wrap_content"
                                    android:textAppearance="?android:attr/textAppearanceLarge"
                                    android:text="Etat"
                                    android:id="@+id/textView2" />

                                <Spinner
                                    android:layout_marginTop="10dp"
                                    android:entries="@array/etat"
                                    android:layout_width="match_parent"
                                    android:layout_height="match_parent"
                                    android:id="@+id/spinner2" />

                                <View style="@style/Divider"/>

                                <TextView
                                    android:textColor="@android:color/holo_blue_light"
                                    android:layout_marginTop="20dp"
                                    android:layout_width="wrap_content"
                                    android:layout_height="wrap_content"
                                    android:textAppearance="?android:attr/textAppearanceLarge"
                                    android:text="Région"
                                    android:id="@+id/textView6" />

                                <Spinner
                                    android:layout_marginTop="10dp"
                                    android:layout_width="match_parent"
                                    android:layout_height="wrap_content"
                                    android:entries="@array/localisation"
                                    android:id="@+id/spinner3" />

                                <View style="@style/Divider"/>

                                <TextView
                                    android:textColor="@android:color/holo_blue_light"
                                    android:layout_marginTop="20dp"
                                    android:layout_width="wrap_content"
                                    android:layout_height="wrap_content"
                                    android:textAppearance="?android:attr/textAppearanceLarge"
                                    android:text="Contenu"
                                    android:id="@+id/textView3" />

                                <Spinner
                                    android:layout_marginTop="10dp"
                                    android:entries="@array/contenu"
                                    android:layout_width="match_parent"
                                    android:layout_height="wrap_content"
                                    android:id="@+id/spinner4"
                                    android:layout_gravity="center_horizontal" />

                            </LinearLayout>

                        </android.support.v7.widget.CardView>

                    </LinearLayout>

                    <LinearLayout
                        android:layout_width="fill_parent"
                        android:layout_height="match_parent"
                        android:layout_gravity="bottom"
                        android:layout_marginBottom="10dp"
                        android:layout_weight=".1" >

                        <android.support.v7.widget.CardView
                            xmlns:card_view="http://schemas.android.com/apk/res-auto"
                            android:id="@+id/card_view2"
                            android:layout_marginTop="10dp"
                            android:layout_marginLeft="10dp"
                            android:layout_marginRight="10dp"
                            android:layout_marginBottom="10dp"
                            android:layout_width="fill_parent"
                            android:layout_height="wrap_content">

                            <LinearLayout
                                android:id="@+id/fragmentContainer2"
                                android:layout_width="match_parent"
                                android:layout_height="match_parent"
                                android:orientation="vertical"
                                android:layout_marginLeft="10dp">

                                <EditText
                                    android:textColor="@android:color/holo_blue_light"
                                    android:layout_marginTop="20dp"
                                    android:layout_width="match_parent"
                                    android:layout_height="wrap_content"
                                    android:id="@+id/editText"
                                    android:layout_marginBottom="10dp"
                                    android:hint="Ecrire un commentaire" />
                            </LinearLayout>

                        </android.support.v7.widget.CardView>

                    </LinearLayout>

                </LinearLayout>

        </LinearLayout>

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

    <com.github.clans.fab.FloatingActionMenu
        android:id="@+id/menu_down"
        android:layout_width="match_parent"
        android:layout_height="37dp"
        android:layout_alignParentRight="true"
        android:layout_marginTop="185dp"
        android:paddingRight="10dp"
        android:paddingTop="10dp"
        android:paddingLeft="10dp"
        android:elevation="6dp"
        fab:menu_labels_ellipsize="end"
        fab:menu_labels_singleLine="true"
        app:layout_anchor="@id/image"
        app:layout_anchorGravity="bottom|right|end"
        fab:menu_openDirection="down">

        <com.github.clans.fab.FloatingActionButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            fab:fab_size="mini"
            fab:fab_label="Menu item 1" />

        <com.github.clans.fab.FloatingActionButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            fab:fab_size="mini"
            fab:fab_label="Menu item 2" />

    </com.github.clans.fab.FloatingActionMenu>

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

我的代码片段:

    public class ConsoleSql extends AppCompatActivity  {

    private JvAdapter mDbHelper;
    TextView Titre;
    Spinner spin_console;
    Spinner spin_etat;
    Spinner spin_region;
    Spinner spin_contenu;
    EditText commentaire;
    String value;
    CollapsingToolbarLayout collapsingToolbarLayout;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.customconsole);
    Toolbar myToolbar = (Toolbar) findViewById(toolbar);
    collapsingToolbarLayout = (CollapsingToolbarLayout) findViewById(R.id.CollapsingToolbarLayout1);

    myToolbar.setTitle("Ajout console");
    setSupportActionBar(myToolbar);
    getSupportActionBar().setDisplayShowTitleEnabled(false);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setHomeAsUpIndicator(R.drawable.ic_close);

    spin_console = (Spinner) findViewById(R.id.spinner);
    spin_etat = (Spinner) findViewById(R.id.spinner2);
    spin_region = (Spinner) findViewById(R.id.spinner3);
    spin_contenu = (Spinner) findViewById(R.id.spinner4);
    commentaire = (EditText) findViewById(R.id.editText);


    Bundle extras = getIntent().getExtras();
    if (extras != null) {
        value = extras.getString("constructeur");
        int arryid = this.getResources().getIdentifier(value, "array", this.getPackageName());
        collapsingToolbarLayout.setTitle("Console "+value);
        ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, arryid, android.R.layout.simple_spinner_item);                    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        spin_console.setAdapter(adapter);

        }

    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.consolemenu, menu);

    return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        int id = item.getItemId();

        if (id == R.id.action_save) {
            mDbHelper = new JvAdapter(this);
            mDbHelper.open();
            //do some stuffs...
            return true;
        }

    return super.onOptionsItemSelected(item);
}
公共类控制台SQL扩展了AppCompatActivity{
私人JvAdapter mDbHelper;
文本视图滴定;
旋转器旋转控制台;
旋转器旋转;
自旋环自旋区;
旋转器旋转内容;
编辑文本评论;
字符串值;
折叠工具栏布局折叠工具栏布局;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.customconsole);
工具栏myToolbar=(工具栏)findViewById(工具栏);
CollasingToolbarLayout=(CollasingToolbarLayout)findViewById(R.id.CollasingToolbarLayout1);
设置标题(“Ajout控制台”);
设置支持操作栏(myToolbar);
getSupportActionBar().setDisplayShowTitleEnabled(false);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeAsUpIndicator(R.drawable.ic_close);
spin_控制台=(微调器)findViewById(R.id.Spinner);
spin_etat=(微调器)findviewbyd(R.id.spinner2);
spin_区域=(微调器)findViewById(R.id.spinner3);
spin_contenu=(微调器)findViewById(R.id.spinner4);
commentaire=(EditText)findViewById(R.id.EditText);
Bundle extras=getIntent().getExtras();
如果(附加值!=null){
value=extras.getString(“constructeur”);
int arryid=this.getResources().getIdentifier(值“array”,this.getPackageName());
折叠ToolbarLayout.setTitle(“控制台”+值);
ArrayAdapter=ArrayAdapter.createFromResource(此、arryid、android.R.layout.simple\u微调器\u项);adapter.setDropDownViewResource(android.R.layout.simple\u微调器\u下拉项);
旋转控制台。设置适配器(适配器);
}
}
@凌驾
公共布尔onCreateOptions菜单(菜单){
getMenuInflater().充气(R.menu.consolemenu,menu);
返回true;
}
@凌驾
公共布尔值onOptionsItemSelected(菜单项项){
int id=item.getItemId();
if(id==R.id.action\u save){
mDbHelper=新的JVAAdapter(本);
mDbHelper.open();
//做一些事情。。。
返回true;
}
返回super.onOptionsItemSelected(项目);
}

将布局锚更改为“appbarlayout”而不是“image”


将布局锚更改为“appbarlayout”而不是“image”



你能提供你的需求的图片表示吗?嗨,首先,谢谢你的回答。这是我的:这是我向下滚动时的结果:我尝试在滚动时将FAB固定在标题上。你能提供你的需求的图片表示吗?嗨,首先,谢谢你的回答。所以t这就是我所拥有的:这就是我向下滚动时所拥有的:我尝试在滚动时将FAB固定到标题。结果相同,但如果我将FAB juste放在代码的工具栏下,则工作…几乎。我的屏幕截图:相同的结果,但如果我将FAB juste放在代码的工具栏下,则工作…几乎。我的屏幕截图:
<com.github.clans.fab.FloatingActionMenu
        android:id="@+id/menu_down"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:elevation="6dp"
        fab:menu_labels_ellipsize="end"
        fab:menu_labels_singleLine="true"
        app:layout_anchor="@id/appbarlayout"
        app:layout_anchorGravity="bottom|end"
        fab:menu_openDirection="down">


</com.github.clans.fab.FloatingActionMenu>