标签: android-appbarlayout

向上滚动时使工具栏变为透明,并在向下滚动时使其可见

当我们向下滚动RecyclerView时,我只想让android.support.v7.widget.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/coordinatorlayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
>

<android.support.design.widget.AppBarLayout
    android:id="@+id/appbarlayout1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    >
    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar1"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="#ae43ff"
        />
    <ImageView
        android:id="@+id/imageview1"
        android:layout_width="match_parent"
        android:layout_height="200dp"
        android:src="@drawable/unnamed"
        android:scaleType="center"
        app:layout_scrollFlags="scroll"
        />

    <!--app:layout_scrollFlags="scroll|enterAlways"-->

    <!--app:layout_collapseMode="parallax"
    app:layout_collapseParallaxMultiplier="0.7"-->
</android.support.design.widget.AppBarLayout>

<android.support.v7.widget.RecyclerView
    android:id="@+id/recyclerview1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    android:background="#6fffc6">

</android.support.v7.widget.RecyclerView>
Run Code Online (Sandbox Code Playgroud)

而我正在获得的输出

在此输入图像描述

我尝试了许多不同的方法,但它不能按我的意愿工作.

我不想要我们在android.support.design.widget.CollapsingToolbarLayout中得到的效果

我想要这个视频中显示的效果

android android-toolbar android-collapsingtoolbarlayout android-appbarlayout

0
推荐指数
1
解决办法
5325
查看次数

使用CollapsingToolbarLayout在嵌套布局中破坏Animate布局更改

我的活动中有以下布局:

CoordinatorLayout ?? AppBarLayout ? ?? CollapsibleToolbarLayout ? ?? TextView (parallax) ? ?? TextView (pin) ? ?? Toolbar ?? NestedScrollView ?? LinearLayout ?? TextView 1 ?? LinearLayout 1 ? ?? 1 to n Views (dynamically added/removed) ... ?? TextView n ?? LinearLayout n ?? 1 to n Views (dynamically added/removed)

当我将Layouts中的animateLayoutChanges设置为true时,无论何时在NestedScrollView内部发生布局更改,结果布局都会与AppBarLayout的内容重叠.

我尝试了这个stackoverflow评论中的建议,但它没有帮助.

有没有人有类似/相同的问题,并找到了解决方案?

android android-animation android-layout android-collapsingtoolbarlayout android-appbarlayout

0
推荐指数
1
解决办法
1395
查看次数

想要锁定 AppBarLayout 的某些片段

我希望 AppBarLayout 对某些片段保持折叠状态,并对其他片段保持打开状态..基本上,我正在寻找一个函数调用,它将以编程方式使 appbarlayout 折叠/取消折叠....我已经尝试了在此列出的几乎所有方法堆栈在流程页面上,但没有一个对我有用。有人可以帮忙吗?

类似的堆栈溢出页面,在这里尝试了大部分内容但不起作用。 需要禁用某些片段的 CollapsingToolbarLayout 上的扩展

谢谢你的时间

Layout file 


    <?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"
        android:fitsSystemWindows="true"
        tools:context="app.com.navact.MainActivity">

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

            <android.support.design.widget.CollapsingToolbarLayout
                android:id="@+id/collapsing_toolbar"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                app:layout_scrollFlags="scroll|exitUntilCollapsed"
                android:fitsSystemWindows="true"
                app:contentScrim="?attr/colorPrimary"
                app:expandedTitleMarginStart="48dp"
                app:expandedTitleMarginEnd="64dp">

            <ImageView
                android:id="@+id/backdrop"
                android:layout_width="match_parent"
                android:layout_height="256dp"
                android:scaleType="centerCrop"
                android:fitsSystemWindows="true"
                app:layout_collapseMode="parallax" />

            <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.CollapsingToolbarLayout>
        </android.support.design.widget.AppBarLayout>


        <FrameLayout
            android:id="@+id/fragment_container"
            android:orientation="vertical"
            android:paddingTop="0dip"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layout_behavior="@string/appbar_scrolling_view_behavior">
         </FrameLayout>

        <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>
Run Code Online (Sandbox Code Playgroud)

android android-appbarlayout

0
推荐指数
1
解决办法
1322
查看次数

ANDROID:膨胀类android.support.design.widget.AppBarLayout时出错

我在布局中添加了一个工具栏,现在运行时出现此错误:

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.myapp/mainactivity.MainActivity}: android.view.InflateException: Binary XML file line #9: Binary XML file line #2: Error inflating class android.support.design.widget.AppBarLayout
Run Code Online (Sandbox Code Playgroud)

这是我的活动布局:

<androidx.constraintlayout.widget.ConstraintLayout
    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">

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

</androidx.constraintlayout.widget.ConstraintLayout>
Run Code Online (Sandbox Code Playgroud)

这是我的应用栏布局:

<android.support.design.widget.AppBarLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/app_bar"
    android:theme="@style/Theme.AppCompat.Light.DarkActionBar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        android:elevation="4dp"
        android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
        app:popupTheme="@style/ThemeOverlay.AppCompat.Light" >

    </android.support.v7.widget.Toolbar>

</android.support.design.widget.AppBarLayout>
Run Code Online (Sandbox Code Playgroud)

在我的活动onCreate()中:

Toolbar toolbar = findViewById(R.id.toolbar);
        if (toolbar != null) {
            setSupportActionBar(toolbar);
            toolbar.setTitle(getTitle());
        }
Run Code Online (Sandbox Code Playgroud)

我不知道为什么。有什么建议么?

android android-toolbar android-appbarlayout androidx

0
推荐指数
2
解决办法
5118
查看次数