我可以设法toolbar
从顶部滚动,这也向下移动主滚动布局。
以下是我当前的解决方案,我设法使底部布局向上滚动与向下滚动的顶部布局平行。但是,底部布局仅与主滚动视图重叠,但我希望它调整主视图的大小以仅显示底部布局之上。与顶视图相同的行为,但仅从底部。
任何人都可以帮助解决这个问题吗?
我的布局:
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/clMain"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:id="@+id/ablSidebar"
android:background="@null"
app:elevation="0dp"
app:contentInsetLeft="0dp"
app:contentInsetStart="0dp"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:background="@null"
app:elevation="0dp"
app:contentInsetLeft="0dp"
app:contentInsetStart="0dp"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_scrollFlags="scroll|enterAlways">
</android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>
<android.support.v7.widget.RecyclerView
android:id="@+id/rvSidebar"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
<LinearLayout
android:id="@+id/llT9"
android:orientation="vertical"
android:layout_gravity="end|bottom"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_behavior="...TextInputScrollingBehaviour">
// ...
</LinearLayout>
</android.support.design.widget.CoordinatorLayout>
还有我的自定义布局行为:
public class TextInputScrollingBehaviour extends CoordinatorLayout.Behavior<LinearLayout> {
private int toolbarHeight;
public TextInputScrollingBehaviour(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
public boolean layoutDependsOn(CoordinatorLayout parent, LinearLayout ll, View dependency) {
return dependency instanceof AppBarLayout;
}
@Override
public boolean onDependentViewChanged(CoordinatorLayout parent, LinearLayout ll, View dependency) {
if (dependency instanceof AppBarLayout) {
CoordinatorLayout.LayoutParams lp = (CoordinatorLayout.LayoutParams) ll.getLayoutParams();
int llBottomMargin = lp.bottomMargin;
int distanceToScroll = ll.getHeight() + llBottomMargin;
float ratio = (float)dependency.getY()/(float)toolbarHeight;
ll.setTranslationY(-distanceToScroll * ratio);
}
return true;
}
}