android - 删除小吃店时向下移动视图/按钮
问题描述
所以我有以下基本代码,以确保在出现小吃店时我的按钮会上升:
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 child, 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>
结果如下所示:
效果很好,但是问题是,如果我通过向左/向右滑动来移除小吃栏,按钮将保持在“上部”位置:
我怎样才能检测到我的小吃店的 MovingDown/Sliding 到正确的行为。我错过了什么重要的事情吗?
解决方案
推荐阅读
- c# - 创建一个静态方法来访问实例列表的属性
- javascript - “TypeError:无法读取未定义的属性‘scopedFn’”。这是什么?
- python-3.x - python语法有什么问题?
- sql - SQL Server Only Allow True for One of Each Type
- typescript - TypeScript:是否可以通过从抽象类中指定的类型继承的属性来实现抽象类属性?
- python - 问题识别原因:ValueError: infinity or too large AFTER normalization
- swift - 创建一个可从所有视图控制器访问的变量
- javascript - 更新behaviorsubject中的特定元素,或者只订阅一次
- javascript - 这是什么意思 IE GIVES error on following code
- r - 如何找到因子列和数值列之间的比率?