将 list_content 包含到列表布局中以保留 ListFragment 功能
首先,我在 1.6(Donut) 中使用 Android 兼容性库 V4 rev.3
当您第一次创建 ListFragment 时,它会显示一个不确定的进度指示器,直到您使用 setListAdabpter() 为止。根据ListFragment.onCreateView的文档,如果我想使用自定义布局:
如果您使用自己的自定义内容覆盖此方法, 考虑包括标准布局{@link android.R.layout#list_content} 在你的布局文件中,这样你 继续保留 ListFragment 的所有标准行为。在 特别是,这是目前拥有内置功能的唯一方法 显示不确定的进度状态。
问题是,当我进入布局文件并尝试:
它(eclipse)告诉我
资源不公开。 (在“layout”处,值为“@android:layout/list_content”)。
我认为这意味着我的 V4 源代码中不存在 list_content.xml
。这是正确的,因为根据文档,它出现在 API v11 中。
我只是假设它会存在于兼容性库源代码中,不知道是否存在...
我能看到的唯一其他解决方案是挖掘 android 的 API V11 源代码并复制并粘贴 list_content.xml.但现在我想避免这种黑客行为。这是唯一的解决方案吗?
First of, I'm using The Android Compatibility Library V4 rev.3 for my 1.6(Donut)
When you first create a ListFragment it displays an indeterminant progress indicator untill you use setListAdabpter(). According to the documentation of ListFragment.onCreateView, if I want to use a custom lay out:
If you are overriding this method with your own custom content,
consider including the standard layout {@link
android.R.layout#list_content} in your layout file, so that you
continue to retain all of the standard behavior of ListFragment. In
particular, this is currently the only way to have the built-in
indeterminant progress state be shown.
The problem is that when I go into my layout file and try:<include layout="@android:layout/list_content" ...>
it (eclipse) tells me that
Resource is not public. (at 'layout' with value '@android:layout/list_content').
I take that to mean list_content.xml
doesn't exist in my V4 source code. which is correct because according to the docs it appeared in API v11.
I just assumed it would exist in the compatibility library source, don't know if it does...
The only other solution I can see would be to dig android's API V11 source code and copy and paste list_content.xml
. For now however I would like to avoid this hackery. is this the only solution?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
兼容性库中包含的
ListFragment
似乎并未像真正的布局那样使用该布局 (list_content)。这可能是因为它是作为 jar 提供的,并且无法打包资源。以下是其onCreateView
的内容:来自兼容性库的 ListFragment:
来自 Android 4.0 的 ListFragment:
考虑到从 APIv11 源代码复制布局文件和包含此视图初始化代码之间的选择,我认为很清楚是哪一个将被视为“黑客”;)
The
ListFragment
included in the compatibility library doesn't appear to use that layout (list_content) as the real one does. This might be because it is offered as a jar and it is not possible to package resources. Here are the contents of itsonCreateView
:ListFragment from compatibility library:
ListFragment from Android 4.0:
Given the choice between copying the layout file from APIv11 source and including this view initialisation code, I think it is clear which one would be considered 'hackery' ;)
我很沮丧地发现 list_content 布局无法使用支持库。我的方法只是重用 ListFragment 的默认 onCreateView 方法,并将其添加为自定义布局的一部分:
我添加了一个 FrameLayout,其中 ListView 曾经位于我的自定义布局中。
I was frustrated to see that the list_content layout was not available using the support library. My approach was simply to reuse the default onCreateView method of the ListFragment and add it as a part of my custom layout:
I added a FrameLayout where the ListView used to be in my custom layout.
使用兼容性库时将默认 @android.R.layout/list_content 合并到自定义布局中的一种可能的解决方法是创建一个虚拟 ListFragment:
然后将这个片段(而不是推荐的 list_content 布局)包含到您的自定义布局:
这样您将获得 ListFragment 的功能齐全的默认行为,同时仍具有自定义布局。
One possible work-around to incorporate default @android.R.layout/list_content into custom layout when using compatibility library is to create a dummy ListFragment:
Then including this fragment (instead of recommended list_content layout) into your custom layout:
This way you'll get a fully functional default behavior of the ListFragment while still having custom layout for it.