删除小吃店时向下移动视图/按钮

问题描述

所以我有以下基本代码,以确保当零食栏出现时我的按钮会出现:

public class MoveUpwardBehavior extends CoordinatorLayout.Behavior<View> {
    private static final boolean SNACKBAR_BEHAVIOR_ENABLED;

    @Override
    public boolean layoutDependsOn(CoordinatorLayout parent,View child,View dependency) {
        return SNACKBAR_BEHAVIOR_ENABLED && dependency instanceof Snackbar.SnackbarLayout;
    }

    @Override
    public boolean onDependentViewChanged(CoordinatorLayout parent,View dependency) {
        float translationY = Math.min(0,dependency.getTranslationY() - dependency.getHeight());
        child.setTranslationY(translationY);
        return true;
    }

    static {
        SNACKBAR_BEHAVIOR_ENABLED = Build.VERSION.SDK_INT >= 11;
    }
}

我的自定义线性布局:

public class CustomLinearLayout extends LinearLayout implements CoordinatorLayout.AttachedBehavior {

    MoveUpwardBehavior mb = new MoveUpwardBehavior();
    public CustomLinearLayout(Context context) {
        super(context);
    }

    public CustomLinearLayout(Context context,AttributeSet attrs) {
        super(context,attrs);
    }

    public CustomLinearLayout(Context context,AttributeSet attrs,int defStyleAttr) {
        super(context,attrs,defStyleAttr);
    }

    @NonNull
    @Override
    public CoordinatorLayout.Behavior getBehavior() {
        return mb;
    }
}

最后但并非最不重要的是我的布局:

<?xml version="1.0" encoding="utf-8"?>
 <androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:tools="http://schemas.android.com/tools"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 xmlns:app="http://schemas.android.com/apk/res-auto"
 app:layout_behavior=".pkgActivity.MoveUpwardBehavIoUr"
 tools:context=".pkgTestforend.DriverListFragment">


    <ListView
        android:id="@+id/listAllDrivers"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >
    </ListView>


    <com.example.dochjavatestimplementation.pkgTestforend.CustomLinearLayout
        android:layout_width="match_parent"
        android:id="@+id/cusll"
        android:layout_height="match_parent"
        >

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">
            <com.google.android.material.floatingactionbutton.FloatingActionButton
                android:id="@+id/btnopenDriverAddFragment2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/baseline_person_add_24"
                />

        </RelativeLayout>

    </com.example.dochjavatestimplementation.pkgTestforend.CustomLinearLayout>


</androidx.coordinatorlayout.widget.CoordinatorLayout>

结果如下:

right result

哪个工作得很好,但是问题是如果我通过向左/向右滑动来移除小吃店,按钮会保持在“上”位置:

button down

如何检测我的小吃店的下移/滑动到正确的行为。我错过了什么重要的事情吗?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...