[英]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
,所以我做了以下步骤:
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.我发现唯一奇怪的是用于
Adapter
的XML
被称为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_list
和R.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_list
和R.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.