简体   繁体   English

Android Studio XML 布局文件存在但我找不到它

[英]Android Studio XML Layout file exist but I can't find it

I wanted to create a Fragment in Android Studio , so I did the following steps:我想在Android Studio 中创建一个Fragment ,所以我做了以下步骤:

  1. Right click on package右键单击包
  2. New -> Android (Other) -> Fragment (List)新建 -> Android(其他)-> 片段(列表)
  3. Checked both include fragment factory methods?检查都包括片段工厂方法? and switch to grid view on large screens在大屏幕上切换到网格视图

The description said "Creates a new fragment containing a list that can optionally change to grid when on large screens."描述说“创建一个包含列表的新片段,在大屏幕上可以选择更改为网格。”

Here's the funny part: As I was reading the code to understand how this switching is done, I could not find any code that switched XML files or anything.下面是有趣的部分:当我阅读代码来了解这种切换是怎么做的,我无法找到任何转换代码XML文件或任何东西。 The only odd thing that I found is that the XML used for the Adapter was called R.layout.fragment_item , but there was no XML called like that in my layout folder.我发现唯一奇怪的是用于AdapterXML被称为R.layout.fragment_item但在我的布局文件夹中没有这样调用的 XML。

There were 2 XML called R.layout.fragment_item_list and R.layout.fragment_item_grid .有 2 个 XML 称为R.layout.fragment_item_listR.layout.fragment_item_grid So I though "hey, maybe internally the framework auto decide if going for _grid or _list and that's why it doesn't mark R.layout.fragment_item it as non-existent"所以我虽然“嘿,也许框架内部会自动决定是使用_grid还是_list ,这就是为什么它没有将R.layout.fragment_item标记为不存在”

When I was done reading the code, I deleted both R.layout.fragment_item_list and R.layout.fragment_item_grid from my layout folder and guess what?当我读完代码后,我从我的布局文件夹中删除了R.layout.fragment_item_listR.layout.fragment_item_grid ,你猜怎么着? R.layout.fragment_item is NOT marked as non-existent, and there is no such file inside my Layout folder. R.layout.fragment_item没有被标记为不存在,并且我的 Layout 文件夹中没有这样的文件。

I already went Build > Clean and Build > Rebuild Project and it still marks it as existent.我已经去了Build > Clean and Build > Rebuild Project并且它仍然将它标记为存在。 Am I missing something here?我在这里错过了什么吗? sounds like there is some basic stuff I haven't taken into account.听起来有些基本的东西我没有考虑到。

Just found what was going on.刚刚发现是怎么回事。 Inside values/refs.xml there was <item name="fragment_item" type="layout">@layout/fragment_item_grid</item> which should be the cause of it.values/refs.xml<item name="fragment_item" type="layout">@layout/fragment_item_grid</item>这应该是它的原因。

I had the same issue, I didn't understand your solution as I couldn't see refs.xml in the values folder.我遇到了同样的问题,我不明白您的解决方案,因为我在 values 文件夹中看不到 refs.xml。

For anybody out there, this is what worked for me: In Android Studio go to File -> Invalidate Caches / Restart...对于那里的任何人,这对我有用:在 Android Studio 中,转到File -> Invalidate Caches / Restart...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我可以在 android studio 中使用布局检查器工具找到特定文件(Activity 或 xml 文件)的路径吗 - Can i find the path of particular file (Activity or xml file) usign layout inspector tool in android studio 我可以在 Android Studio 中为布局文件的 xml 元素添加注释吗? - Can I add a comment for xml element of layout file in Android Studio? 我在 Android Studio 的 XML 文件中找不到“设计”选项卡 - I can't find the Design tab in my XML file in Android Studio 我在 Android Studio 中找不到 R 文件? - I can't find the R-File In Android Studio? Android Studio无法识别布局中的xml文件 - Android Studio don't recognise xml file in layout Android Studio无法解析新的XML布局 - Android Studio can't resolve new XML layout 如何使用Android Studio在应用程序内的xml文件布局中实现? - How can I implement from xml file layout inside the App using Android studio? 是否可以使SMALL XML的Android Studio布局资源文件包含Nexus ONE和Nexus S手机? - Can I make the Android Studio Layout Resource File for SMALL XML include Nexus ONE and Nexus S phones? 尝试在android项目中创建新布局时找不到xml创建选项 - I can't find the create xml option while trying to create a new layout in android project Android Studio 找不到从布局生成的 kotlinx 模块 - Android Studio can't find kotlinx module generated from layout
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM