【发布时间】:2017-02-26 11:00:07
【问题描述】:
我使用的是ScrollingActivity,它带有CollapsingToolbarLayout。我想在这个布局中添加一个ImageView,并且能够以编程方式切换图像,但它似乎没有做任何事情。
我的布局的 XML:
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/toolbar_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin"
app:popupTheme="@style/AppTheme.PopupOverlay" />
<ImageView
android:id="@+id/header_logo"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="center"
android:layout_gravity="center"
app:layout_collapseMode="parallax"
/>
</android.support.design.widget.CollapsingToolbarLayout>
当我尝试在某个事件中执行以下操作时:
ImageView im = (ImageView)findViewById(R.id.toolbar_layout);
im.setBitmap(image_here);
但是当我触发这个事件时,什么都没有发生。我知道我的图像被正确解析,因为事实上我没有从中得到任何异常;在整个过程中,我根本没有遇到任何异常。我在这里做错了吗?有没有办法刷新此工具栏以更新图像?
【问题讨论】:
-
我认为这是因为
R.id.toolbar_layout是CoordinatorLayout的id而不是ImageView的id。将其更改为R.id.header_logo
标签: android android-layout imageview android-toolbar