代码之家  ›  专栏  ›  技术社区  ›  Mojo Risin

更改配置上的映像已更改

  •  6
  • Mojo Risin  · 技术社区  · 14 年前

    有没有一种方法可以在不破坏整个活动的情况下,将ImageView drawable更改为相应的drawable for landscape模式。我试图在onConfigurationChanged回调中再次设置drawable,但它不起作用。像这样的

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

    当我在横向模式下启动活动时,将显示正确的可绘制状态,以便正确定位资源。

    3 回复  |  直到 14 年前
        1
  •  6
  •   Fedor    14 年前

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

    iv.setBackgroundResource(R.drawable.android);
    

    具有

    iv.setImageDrawable(getResources().getDrawable(R.drawable.android));
    

    看看这个
    http://open-pim.com/tmp/ImageTest.zip
    我试过你的方法,对我来说很好。

        2
  •  0
  •   Macarse    14 年前

    有没有办法改变ImageView 破坏整个活动。

    onCreate() 方法被调用。

    如果您想避免这种行为,请使用:

    android:configChanges="orientation|keyboardHidden"
    

    为了你的 Activity AndroidManifest .

    关于你的问题: 我首先会在方向改变后检查它叫什么: onConfigurationChanged onCreate .

    如果 OnConfiguration已更改 setContentView() 在你的 onCreate() ImageView

        3
  •  0
  •   Jehof    13 年前

    对于emulator,除了方向之外,还需要screenLayout来调用方法。

    android:configChanges="orientation|screenLayout"