0

有没有办法在改变方向时自动适应屏幕?

因为当我以纵向模式查看我的应用程序时,所有图像似乎都很好,但是当我将其更改为横向时,图像变得像素化或被拉伸得很多。所以我想知道是否有自动调整屏幕。

感谢您的任何想法。

4

5 回答 5

3

在 layout-land 文件夹中指定具有相同名称的不同布局并使用合适的可绘制对象。如需更多帮助,请参阅本教程

http://www.androidpeople.com/android-portrait-amp-landscape-differeent-layouts

于 2012-11-28T08:54:05.477 回答
1
Display display;
int width;
int height;

在 onCreate() 添加宽度 = display.getWidth(); 高度 = display.getHeight();

在 onResume() 添加

if(width<height){
 //you can add your layout here (landscape)
}else{
    //you can add your layout here (portrait)
}
于 2012-11-29T09:18:33.520 回答
0

您必须有两种布局,一种用于纵向,另一种用于横向。如果您使用两种布局,则可以使用相同的图像。

于 2012-11-28T08:52:00.123 回答
0

有两种可能,

选项 1:您可以在layout-portlayout-landdrawable、中使用不同的 XML 布局drawable-land。在这些 XML 布局中,您可以修复与您的屏幕密度匹配的不同大小的图像。对于不同的图像集,您可以查看ldpimdpihdpixhdpi

选项 2:您可以使用九个补丁图像。

如果您找到更好的解决方案,请分享。

干杯。

于 2012-11-28T09:01:33.263 回答
0

您可以使用以下代码段来识别配置已更改

@Override
public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);

 // Checks the orientation of the screen and do your action here

}

干杯。

于 2012-11-30T11:44:37.383 回答