2013-05-30 123 views
1

我在layout文件夹下有一个login.xml文件;我创建了一个layout-land文件夹,该文件夹出现在布局下方,其中还有一个login.xml文件。在我的Login.java文件中,我可以访问R.layout.loging,但是我无法访问R.layout-land.login。我已经阅读了近两个小时,没有运气。 以下是我迄今所做的:R.layout-land无法解析为变量

  1. 右键点击项目名称,然后选择“新建 - >其他 - > Android的XML布局文件”,然后单击下一步
  2. “login.xml”为文件名, “LinearLayout”用于根元素,然后单击下一步
  3. 单击方向并将其向右移动,然后选择land scape - >它显示/ res/layout-land作为文件夹名称。我点击完成 文件夹用地布局出现下面的文件夹名称的布局和显示如下消息:
  4. 我去项目和清洁
  5. 我去构建路径 - >订单和扩展端口,并确保Android 4.2版本。 2 is
  6. 我确保文件夹名称和/或xml文件名中没有大写或空格
  7. 我再次构建项目时没有运气。
  8. 在构建路径中,我将gen文件夹移动到scr上方。我关闭的项目存在日食。重新打开Eclipse和重建项目
  9. 我检查并没有Android.R *进口

,但没有运气

我的错误信息

[2013-05-29 21:01:46 - Students] 'Landscape Orientation' is not a best match for any device/locale combination. 
[2013-05-29 21:01:46 - Students] Displaying it with ', , Locale Language ___Region __, 
, sw320dp, w533dp, h320dp, Normal Screen, Long screen aspect ratio, Landscape Orientation, 
Normal, Day time, High Density, Finger-based touchscreen, Soft keyboard, No keyboard, 
Hidden navigation, No navigation, Screen resolution 800x480, API Level 17' which is 
compatible, but will actually be displayed with another more specific version of the 
layout. 

以下是我的代码:

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    int result = this.getResources().getConfiguration().orientation; 
    if(result == 1) 
     { 
      setContentView(R.layout.login); 
     } else 
     { 
      setContentView(R.layout-land.login //Issue here. 
     } 
    InitializeVariables(); 
} 

我真的很感谢任何形式的帮助/ sugge Stion的。

回答

0

您可以使用使用 它会自动使用您的布局土地,当它在横向。与任何其他具有其他后缀(如-xlarge,-hdpi)的其他文件夹一样,它们在apporpriate时将自动使用。

更多的参考是在这里对这个page

0

你不需要做这一切时,Android将只要你按照他们制定的惯例选择合适的布局文件你。只需执行setContentView(R.layout.login),系统将使用res/layout/login.xml中的常规文件(如果纵向)和横向文件中的res/layout-land/login.xml中的文件。

1

您不指定文件夹。 Android知道使用哪一个。只需使用,如果是横向那么你Activity会选择正确的Layout

根据The Docs

... Android的选择替代资源在运行时根据当前的设备配置使用的。

+0

谢谢大家。如果我早些时候请求帮助,现在我会进一步深入。谢谢!!!!! –