更改图像onConfigurationChanged

Moj*_*sin 6 user-interface android

有没有办法在不破坏整个活动的情况下,使用相应的drawable for Landscape模式更改ImageView drawable.我尝试在onConfigurationChanged回调中再次设置drawable,但它不起作用.像这样的东西

@Override
public void onConfigurationChanged(Configuration conf) {
    super.onConfigurationChanged(conf);
    mImageView.setImageDrawable(getResources().getDrawable(R.drawable.iv));
}
Run Code Online (Sandbox Code Playgroud)

当我在横向模式中为活动加注星形以显示正确的可绘制时,可以正确定位资源.

Fed*_*dor 6

在您的示例项目中只需替换

iv.setBackgroundResource(R.drawable.android);
Run Code Online (Sandbox Code Playgroud)

iv.setImageDrawable(getResources().getDrawable(R.drawable.android));
Run Code Online (Sandbox Code Playgroud)

我猜setBackgroundResource什么都不做,因为已经为ImageView分配了相同的资源.

看看这个
http://open-pim.com/tmp/ImageTest.zip
我尝试了你的方法,它对我很有用.