包括list_content到列表布局保留ListFragment功能布局、功能、列表、list_content

2023-09-04 12:37:18 作者:穿上婚紗成爲妳的伴娘

首先,我使用的是Android的兼容库V4订正我的1.​​6(甜甜圈)

First of, I'm using The Android Compatibility Library V4 rev.3 for my 1.6(Donut)

当你直到你使用setListAdabpter首先创建它会显示一个不确定的进度指示器一个ListFragment()。据ListFragment.onCreateView的文件,如果我想使用自定义布局:

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:

如果您正在重写此方法与自己的自定义内容,   考虑包括标准布局{@link   android.R.layout#list_content}在布局文件,这样你   继续保留所有ListFragment标准的行为。在   特别是,这是目前有内置的唯一方式   显示不确定的进展状况。

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.

现在的问题是,当我进入我的布局文件,并尝试: <包括布局=@安卓布局/ list_content...> 它(日蚀)告诉我,

The problem is that when I go into my layout file and try: <include layout="@android:layout/list_content" ...> it (eclipse) tells me that

资源是不公开的。 (在布局,值为@android:布局/ list_content')

Resource is not public. (at 'layout' with value '@android:layout/list_content').

我认为这意味着 list_content.xml 不在我的V4源$ C ​​$ C存在。这是正确的,因为根据文档它出现在API V11。

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

唯一的其他解决方案,我可以看到会挖Android的API V11源$ C ​​$ c和复制并粘贴 list_content.xml 。现在不过,我想避免这种两轮牛车。这是唯一的解决办法?

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?

推荐答案

ListFragment 包含在兼容性库没有出现使用该布局(list_content)作为真正的人做。这可能是因为它是作为一个罐子,它是不可能打包资源。以下是内容的 onCreateView

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 its onCreateView:

ListFragment从兼容性库:

ListFragment from compatibility library:

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
    final Context context = getActivity();

    FrameLayout root = new FrameLayout(context);

    // ------------------------------------------------------------------

    LinearLayout pframe = new LinearLayout(context);
    pframe.setId(INTERNAL_PROGRESS_CONTAINER_ID);
    pframe.setOrientation(LinearLayout.VERTICAL);
    pframe.setVisibility(View.GONE);
    pframe.setGravity(Gravity.CENTER);

    ProgressBar progress = new ProgressBar(context, null,
            android.R.attr.progressBarStyleLarge);
    pframe.addView(progress, new FrameLayout.LayoutParams(
            ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));

    root.addView(pframe, new FrameLayout.LayoutParams(
            ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT));

    // ------------------------------------------------------------------

    FrameLayout lframe = new FrameLayout(context);
    lframe.setId(INTERNAL_LIST_CONTAINER_ID);

    TextView tv = new TextView(getActivity());
    tv.setId(INTERNAL_EMPTY_ID);
    tv.setGravity(Gravity.CENTER);
    lframe.addView(tv, new FrameLayout.LayoutParams(
            ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT));

    ListView lv = new ListView(getActivity());
    lv.setId(android.R.id.list);
    lv.setDrawSelectorOnTop(false);
    lframe.addView(lv, new FrameLayout.LayoutParams(
            ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT));

    root.addView(lframe, new FrameLayout.LayoutParams(
            ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT));

    // ------------------------------------------------------------------

    root.setLayoutParams(new FrameLayout.LayoutParams(
            ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT));

    return root;
}

ListFragment从Android 4.0的:

ListFragment from Android 4.0:

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    return inflater.inflate(com.android.internal.R.layout.list_content, container, false);
}

由于抄袭APIv11源布局文件,包括这个观点初始化code之间进行选择,我认为这是明显的哪一个会被认为是两轮牛车')

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' ;)

 
精彩推荐
图片推荐