因此我无法动态调整Imageview的大小。我正在使用Spotify SDK,对于专辑封面,我希望根据底部工作表滚动偏移调整图像大小。
首先,我只能发布1个链接here's an album with screenshots
因此左下角的图像(链接中的第一个图像)应调整为链接中的第二个图像。这是底页(框架布局)中的简单图像视图,这是我的代码:
mBottomSheetBehaviour.setBottomSheetCallback(new BottomSheetBehavior.BottomSheetCallback() {
@Override
public void onStateChanged(@NonNull View bottomSheet, int newState) {
int state = newState == BottomSheetBehavior.STATE_EXPANDED ? View.VISIBLE : View.GONE;
mCloseSheetButton.setVisibility( state );
}
@Override
public void onSlide(@NonNull View bottomSheet, float slideOffset) {
// Animate fab
int width = bottomSheet.getWidth();
int translationX = (int) ((-width / 2f + mFAB.getWidth() / 2f + dpToPx(16) ) * slideOffset);
mFAB.setTranslationX(translationX);
float imgWidth = Math.max(getResources().getDimension(R.dimen.abc_action_bar_default_height_material), width * slideOffset);
Log.e("test", "onSlide: max " + imgWidth);
Log.e("test", "onSlide: img" + String.valueOf(mAlbumArt.getLayoutParams().height));
mAlbumArt.getLayoutParams().height = (int) (imgWidth);
mAlbumArt.getLayoutParams().width = (int) (imgWidth);
mAlbumArt.requestLayout();
// tried this, but does nothing: mAlbumArt.invalidate();
}
});
我可以看到日志,他们说大小正在变化,但图像保持较小(第三张图像)。最奇怪的是,当我按下播放/暂停时,图像会调整大小(只有当底页完全展开或根本没有展开时,滚动时才能这样做)。播放/暂停由SDK处理,我只调用此函数:
private void updateButtons() {
boolean loggedIn = isLoggedIn();
mFAB.setImageResource(mYfitopsHelper.isPlaying() ? android.R.drawable.ic_media_pause : android.R.drawable.ic_media_play);
// Login button should be the inverse of the logged in state
Button loginButton = (Button) findViewById(R.id.login_button);
loginButton.setText(loggedIn ? R.string.logout_button_label : R.string.login_button_label);
// Set enabled for all widgets which depend on initialized state
for (int id : REQUIRES_INITIALIZED_STATE) {
findViewById(id).setEnabled(loggedIn);
}
// Same goes for the playing state
boolean playing = loggedIn && mYfitopsHelper.mCurrentPlayerState.trackUri != null;
for (int id : REQUIRES_PLAYING_STATE) {
findViewById(id).setEnabled(playing);
}
}
我不明白为什么只在按下其中一个按钮时才更新Imageview ...有什么建议吗?