如何使用风景模式和肖像模式之间2种不同的背景 [英] How can I use 2 different background between landscape mode and portrait mode

查看:289
本文介绍了如何使用风景模式和肖像模式之间2种不同的背景的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Android应用程序,我想知道如果我能有1布局(1布局的xml文件),风景和肖像模式。但我想不同的背景,每一种模式?那可能吗?我需要2 XML文件指向不同的背景图片?或者,我可以实现我想用1 xml文件?

I have an android application, I would like to know if I can have 1 layout (1 layout xml file) for both landscape and portrait mode. But I want a different background for each mode? Is that possible? Do I need 2 xml file points to different background image? Or I can achieve what I want using 1 xml file?

感谢你。

推荐答案

如果你愿意用code做到这一点,你可以尝试插入类似

If you're willing to use code to accomplish this, you might try inserting something like

View view = (View) findViewById(R.id.background_carrying_view);
int orientation = getResources().getConfiguration().orientation;
if(orientation == Configuration.ORIENTATION_LANDSCAPE) {
    view.setBackgroundResource (R.drawable.background_land);
} else {
    view.setBackgroundResource (R.drawable.background_port);
}

到您的onCreate()和/或onConfigurationChange()。

into your onCreate() and/or onConfigurationChange().

通过这种方法,你可以使用相同的布局进行横向和纵向。

With this method, you would use the same layout for both landscape and portrait.

这篇关于如何使用风景模式和肖像模式之间2种不同的背景的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆