【发布时间】:2016-11-25 05:56:29
【问题描述】:
按照this 教程,我有这个CollapsingToolbarLayout:
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/toolbar_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:contentScrim="?attr/colorPrimary"
app:layout_scrollFlags="scroll|enterAlways|enterAlwaysCollapsed">
<ImageView
android:id="@+id/blurred_background"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:ignore="ContentDescription" />
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:src="@drawable/defaultimage"
app:layout_collapseMode="parallax"
app:layout_collapseParallaxMultiplier="0.7"
tools:ignore="ContentDescription"
android:id="@+id/profilePicture" />
</android.support.design.widget.CollapsingToolbarLayout>
但是,我需要使用setSupportActionBar(),这样我才能使用setTitle()、setHomeAsUpEnabled()等方法。但是,显然CollapsingToolbarLayout 不能转换为Toolbar,并且setSupportActionBar() 方法只接受Toolbar 方法。
有替代的设置方法吗?
【问题讨论】:
-
为什么不把你的
ImageViews 包裹在Toolbar中? -
@MikeM。好主意,但我的
ImageViews 似乎失去了他们所拥有的对齐方式。 (其中一个是居中的,现在它在屏幕的左侧` -
在 ToolBar 中,您也可以像在 LinearLayout 中一样添加所需的子视图,所以是的,您为什么不使用它?
-
谢谢@MikeM。欣赏它。
标签: android android-toolbar android-collapsingtoolbarlayout