如何让小吃店和工厂一起搬家

问题描述 投票:0回答:2

我想移动小吃店和工厂一起移动,就像默认行为一样,但默认情况下,只有当我们点击工厂时才会发生,工厂为snackbar和工厂本身向上移动,

但希望它发生在其他事件发生时,如布局上其他按钮不喜欢自己制造,如何在布局点击其他按钮时触发晶圆厂向上移动并为snackbar腾出位置

谢谢

按下按钮:

 public void onClick(View view) {
             if(spinner.getText().length() <= 0){
                 showListMenu(spinner);
             }else{
                 showSnack("Added to bag we will hold it for 1 hour!", view.getRootView());
             }
        }

里面的showSnack:

 Snackbar.make(view.getRootView(), getResources().getString(R.string.fab_msg), Snackbar.LENGTH_LONG)
                    .setAction("Action", null).show();

    final Animation myAnim = AnimationUtils.loadAnimation(MainActivity.this, R.anim.bounce);
    double animationDuration = 2 * 1000;
    myAnim.setDuration((long)animationDuration);

    MyBounceInterpolator interpolator = new MyBounceInterpolator(0.20, 20.00);

    myAnim.setInterpolator(interpolator);
    fab.startAnimation(myAnim);
android android-coordinatorlayout floating-action-button android-snackbar
2个回答
1
投票

只需用这样的小吃吧锚定fab:

Snackbar.make(view.view.findViewById(R.id.fab), getResources().getString(R.string.fab_msg), Snackbar.LENGTH_LONG)
                .setAction("Action", null).show();

0
投票

使用足够的CoordinatorLayout,无需在Java代码上进行任何更改。在CoordinatorLayout中添加按钮

    <?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"
    tools:context=".MainActivity">

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/AppTheme.AppBarOverlay">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:popupTheme="@style/AppTheme.PopupOverlay" />

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

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

    <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:srcCompat="@android:drawable/ic_dialog_email" />

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

对于这两个点击事件,SnackBarFab顺利上升

  fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                    .setAction("Action", null).show();
        }
    });

    toolbar.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Snackbar.make(v, "Replace with your own action", Snackbar.LENGTH_LONG)
                    .setAction("Action", null).show();
        }
    });
© www.soinside.com 2019 - 2024. All rights reserved.