0

作为 android 的新手,并且要求在更改手机方向时 imageview src 图像会发生变化(纵向到横向,反之亦然)。为 imageview 设置图像对我来说是可以的,但是如何才能实现上述要求。这件事可能吗在安卓。谢谢。一点帮助将不胜感激。这里我提到了两个包含一些图像视图的布局

1 纵向设计模式

应用程序的肖像设计

2.设计的横向模式 应用程序的景观设计 如果还有什么需要请问我。该应用程序是为 android 版本 2.3 和 api 级别 10 设计的

4

4 回答 4

1

尝试这个。

@Override
public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);
    ImageView imageView = (ImageView)findViewById(R.id.imageView);
    if(getResources().getConfiguration().orientation == 2) {
        imageView.setImageDrawable(R.drawable.landscapeimage);
    } else if(getResources().getConfiguration().orientation == 1){
        imageView.setImageDrawable(R.drawable.portraitimage);
    }
}
于 2013-02-01T05:49:14.423 回答
1

you can create Layout-land and from that you can copy paste your code from the layout folder , and change the imageview to whatever you like. now when the user change orientation it will go to the layout-land. hope that help you.

于 2013-02-01T06:19:32.627 回答
0

您必须创建新布局并将其放入指定的文件夹,例如:

- layout layout-800x400 
- layout-land 
- layout-land-800x400 
- layout-port
- layout-port-1232x800

等等

在每个文件夹中调整布局取决于您希望它是什么样的设计。现在,如果它不起作用,您必须确定设备的尺寸或分辨率并将其添加为您的布局文件夹,如上面的示例,因为设备可能无法找到它的布局文件夹。

如需更多参考,请查看此链接 http://developer.android.com/guide/practices/screens_support.html

于 2013-02-01T07:45:01.680 回答
0

写在 onStart()

Display display = getWindowManager().getDefaultDisplay(); 
int width = display.getWidth();
int height = display.getHeight();

if(width<height){
   //in portrait mode

}
else{
   //in landscape mode.
}
于 2013-02-01T06:08:32.817 回答