Android 将图像设置为页眉折叠工具栏折叠时的布局
我想在折叠时将图像粘贴为Android 将图像设置为页眉折叠工具栏折叠时的布局,android,android-toolbar,android-collapsingtoolbarlayout,Android,Android Toolbar,Android Collapsingtoolbarlayout,我想在折叠时将图像粘贴为折叠工具栏布局的背景。我可以在折叠工具栏布局上以展开形式显示图像,但当折叠的图像消失时,我需要以下GIF图像的效果: 我的结构如下: 任何帮助都将不胜感激,提前感谢。尝试从折叠工具栏布局中删除contentScrim属性首先使用此链接创建它们,并将其设置为活动主题 xml代码如下所示 <android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.
折叠工具栏布局的背景。我可以在折叠工具栏布局
上以展开形式显示图像,但当折叠的图像消失时,我需要以下GIF图像的效果:
我的结构如下:
任何帮助都将不胜感激,提前感谢。尝试从折叠工具栏布局中删除contentScrim
属性
首先使用此链接创建它们,并将其设置为活动主题
xml代码如下所示
<android.support.design.widget.CoordinatorLayout
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="match_parent"
android:fitsSystemWindows="true">
<android.support.design.widget.AppBarLayout
android:id="@+id/app_bar_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
android:fitsSystemWindows="true">
<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"
app:contentScrim="?attr/colorPrimary"
app:expandedTitleMarginStart="48dp"
app:expandedTitleMarginEnd="64dp"
android:fitsSystemWindows="true">
<ImageView
android:id="@+id/image"
android:layout_width="match_parent"
android:layout_height="wrap_content"
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"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
app:layout_collapseMode="pin" />
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
您也可以简单地将contentScrim设置为透明颜色
例如
您的问题解决了吗?我也在寻找这种实现。你是如何实现的?@DevendraSingh,好的,我写下我的答案,从那里你可以使用它。@VikramSingh不,我以为你已经做到了。实际上我在这里贴了一个问题
<android.support.design.widget.CoordinatorLayout
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="match_parent"
android:fitsSystemWindows="true">
<android.support.design.widget.AppBarLayout
android:id="@+id/app_bar_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
android:fitsSystemWindows="true">
<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"
app:contentScrim="?attr/colorPrimary"
app:expandedTitleMarginStart="48dp"
app:expandedTitleMarginEnd="64dp"
android:fitsSystemWindows="true">
<ImageView
android:id="@+id/image"
android:layout_width="match_parent"
android:layout_height="wrap_content"
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"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
app:layout_collapseMode="pin" />
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
collapsingToolbarLayout = (CollapsingToolbarLayout) findViewById(R.id.collapsing_toolbar);
collapsingToolbarLayout.setTitle(itemTitle);
<com.google.android.material.appbar.CollapsingToolbarLayout
android:id="@+id/collapsingToolbarLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:contentScrim="@color/ap_transparent" <-- this line
app:layout_scrollFlags="scroll|exitUntilCollapsed|snap">