android - R.layout-land 无法解析为变量

标签 android android-layout

我在 layout 文件夹下有一个 login.xml 文件;我创建了一个 layout-land 文件夹,它出现在 layout 的正下方,里面也有一个 login.xml 文件。在我的 Login.java 文件中,我可以访问 R.layout.loging,但我无法访问 R.layout-land.login。我已经阅读了将近两个小时,但没有运气。 这是我到目前为止所做的:

  1. 右键点击项目名称,选择“新建->其他->Android XML布局文件”,点击下一步
  2. “login.xml”作为文件名,“LinearLayout”作为根元素,然后单击下一步
  3. 点击 orientation 并将其向右移动并选择 landscape -> 它显示/res/layout-land 作为文件夹名称。我点击完成 文件夹 land-layout 出现在文件夹名称布局下方,并出现以下消息:
  4. 我去项目并清理它
  5. 我转到 Build Path -> Order and Eport 并确保选中 Android 4.2.2
  6. 我再次确保文件夹名称和/或 xml 文件名中没有大写字母或空格
  7. 我再次构建项目,但没有成功。
  8. 在构建路径中,我将 gen 文件夹移到 scr 上方。我关闭项目存在 eclipse。重新打开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();
}

如果有任何帮助/建议,我将不胜感激。

最佳答案

您没有指定文件夹。 Android 知道使用哪一个。只需使用 R.layout.login,如果它是横向的,那么您的 Activity 将选择正确的 Layout

根据 The Docs

...Android selects which alternative resource to use at runtime, depending on the current device configuration.

关于android - R.layout-land 无法解析为变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16826391/

相关文章:

java - Android:将数据从surfaceView传递到其父 Activity

android - 多个 JSON 字段仅在 “RELEASE” 构建模式下命名为异常

android - java.lang.RuntimeException : Unable to create application com. app.MyApp : java. lang.NullPointerException:FirebaseCrashlytics 组件不存在

android - HTML 中的可滚动内容不会在 Android 模拟器或手机中滚动

android - DataBinding 在自定义横向布局膨胀时失败

android - 支持库中带有 ScriptIntrinsicBlur 的图像缺陷

android - 想知道 Galaxy S 的值大小

Android 横向和纵​​向模式变化

android - finditem() 找不到菜单,卡在 NullPointerException

android-layout - 访问 XML 可绘制资源中元素的属性