Android Studio XML Layout文件存在,但我找不到它

时间:2022-01-14 20:53:22

I wanted to create a Fragment in Android Studio, so I did the following steps:

我想在Android Studio中创建一个Fragment,所以我做了以下步骤:

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

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. 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.

这是有趣的部分:当我阅读代码以了解如何完成此切换时,我找不到任何切换XML文件或任何内容的代码。我发现的唯一奇怪的事情是用于适配器的XML被称为R.layout.fragment_item,但是在我的布局文件夹中没有像这样的XML。

There were 2 XML called R.layout.fragment_item_list and 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"

有2个名为R.layout.fragment_item_list和R.layout.fragment_item_grid的XML。所以我虽然“嘿,也许在内部,框架自动决定是否使用_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_gridfrom my layout folder and guess what? R.layout.fragment_item is NOT marked as non-existent, and there is no such file inside my Layout folder.

当我读完代码后,我从布局文件夹中删除了R.layout.fragment_item_list和R.layout.fragment_item_grid并猜猜是什么? R.layout.fragment_item未标记为不存在,并且我的Layout文件夹中没有此类文件。

I already went Build > Clean and Build > Rebuild Project and it still marks it as existent. Am I missing something here? sounds like there is some basic stuff I haven't taken into account.

我已经去了Build> Clean and Build> Rebuild Project,它仍然标记为存在。我在这里错过了什么吗?听起来有些基本的东西我还没有考虑到。

1 个解决方案

#1


5  

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里面有 @ layout / fragment_item_grid ,这应该是它的原因。

#1


5  

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里面有 @ layout / fragment_item_grid ,这应该是它的原因。