【发布时间】:2019-04-04 09:50:04
【问题描述】:
我有一个用于工具栏的布局;
<?xml version="1.0" encoding="utf-8"?>
<merge
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/expanded_collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="120dp"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<android.support.v7.widget.Toolbar
android:id="@+id/expanded_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin"/>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
我在我的布局中使用它;
<com.dan.finance.ui.ExpandedToolbar
android:id="@+id/expandable_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:toolbarNavColor="?attr/NavigationIconColor"
app:toolbarNavIcon="?attr/NavigationUpArrow"
app:toolbarTitle="My Finances"
app:toolbarTitleColor="?attr/NavigationTitleColor"/>
在我的大多数布局中,在此下方我有一个嵌套的滚动视图,我的问题是在默认情况下内容不应滚动的布局上,打开软键盘允许使用 adjustResize 滚动内容,但我的工具栏没有对此做出反应并崩溃。
我的布局的完整代码是;
<?xml version="1.0" encoding="utf-8"?>
<layout 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">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.CoordinatorLayout
android:id="@+id/coordinator_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<com.dan.finance.ui.ExpandedToolbar
android:id="@+id/expandable_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:toolbarNavColor="?attr/NavigationIconColor"
app:toolbarNavIcon="?attr/NavigationUpArrow"
app:toolbarTitle="My Finances"
app:toolbarTitleColor="?attr/NavigationTitleColor"/>
<android.support.v4.widget.NestedScrollView
android:id="@+id/nested_scrollview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
app:layout_anchor="@id/expandable_toolbar"
app:layout_anchorGravity="bottom"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<android.support.constraint.ConstraintLayout
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.AppCompatTextView
android:id="@+id/title"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:paddingStart="32dp"
android:paddingEnd="0dp"
android:text="Finances"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
<android.support.v7.widget.AppCompatEditText
android:id="@+id/edit_text"
android:layout_width="0dp"
android:layout_height="56dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/title"/>
<android.support.v7.widget.AppCompatTextView
android:id="@+id/details"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="DETAILS TODO"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/edit_text"/>
<android.support.v7.widget.RecyclerView android:id="@+id/finances_list"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layoutManager="android.support.v7.widget.LinearLayoutManager"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/details"/>
<android.support.v7.widget.AppCompatButton
android:id="@+id/button_see_all"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="See All"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="@id/finances_list"
app:layout_constraintVertical_bias="1.0"/>
</android.support.constraint.ConstraintLayout>
</android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>
</RelativeLayout>
这个布局作为一个整体不会在大型设备上滚动,但可能会在较小的设备/未来版本上滚动,所以我相信这可能是我的问题所在,但我尝试了很多不同的东西,但没有任何结果.我还尝试使用
以编程方式扩展和折叠工具栏mAppBarLayout.setExpanded(expand, true);
但这不会为我假设的布局设置动画,因为它不在滚动布局中,因为可能没有内容可以显示?
【问题讨论】:
-
看看 ExpandedToolbar 会很有帮助。可以发一下吗
-
@Cheticamp ExpandedToolbar 是顶级sn-p
-
也许我遗漏了一些东西,但 ExpandedToolbar 不是自定义视图吗?我试图了解顶部 sn-p 是如何实际添加到布局中的。我认为发布 ExpandedToolbar 的代码会有所帮助。
-
是的,顶部的代码在一个名为 ExpandedToolbar 的自定义视图中
-
你能发布那个自定义视图吗? ExpandedToolbar.java 还是 ExpandedToolbar.kt?
标签: java android android-collapsingtoolbarlayout