SwipeRefreshLayout只能容纳一个直接子代 [英] SwipeRefreshLayout can host only one direct child
问题描述
我在listView中添加了一个拉动刷新",当列表为空时,我也想添加一个空视图-现在我收到此错误.我该如何进行这项工作?如果我将视图放置在swipeRefresh之外,然后将其添加为emptyView,它将起作用.那我怎么用一个外部xml文件呢?.
I added a "pull to refresh" to my listView, i also wanted to add an empty view when the list is empty - Now i got this error. How can i make this work? if im positioning a view outside of the swipeRefresh and then add it as the emptyView it will work. So how do i so it with an outer xml file .. ?
xml代码:
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/swipeRefreshLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true" >
<ListView
android:id="@android:id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:clipToPadding="false"
android:paddingBottom="@dimen/inbox_vertical_margin" ></ListView>
</android.support.v4.widget.SwipeRefreshLayout>
onCreateView:
onCreateView:
View rootView = inflater.inflate(R.layout.fragment_inbox, container,
false);
View empty = inflater.inflate(R.layout.empty_message_list, container,
false);
ListView mListView = (ListView) rootView
.findViewById(android.R.id.list);
((ViewGroup) mListView.getParent()).addView(empty);
TextView textViewToChange = (TextView) empty
.findViewById(R.id.welcomeMessage);
textViewToChange.setText("YO "
+ ParseUser.getCurrentUser().getString(
ParseConstants.KEY_PRESENTING_USERNAME)
+ "! bad news.. :(");
mListView.setEmptyView(empty);
mSwipeRefreshLayout = (SwipeRefreshLayout) rootView
.findViewById(R.id.swipeRefreshLayout);
mSwipeRefreshLayout.setOnRefreshListener(mOnRefreshListener);
mSwipeRefreshLayout.setColorScheme(R.color.swipeRefresh1,
R.color.swipeRefresh2, R.color.swipeRefresh3,
R.color.swipeRefresh4);
return rootView;
推荐答案
SwipeRefreshLayout
应该是XML文件中的父级.
SwipeRefreshLayout
should be the parent in the XML file.
您可以将FrameLayout
用作SwipeRefreshLayout
的子级. ListView
和TextView
(或任何其他空状态视图)可以是FrameLayout
的子视图.
You can use a FrameLayout
as the child of SwipeRefreshLayout
. The ListView
and TextView
(or any other empty state view) can be child views of the FrameLayout
.
这篇关于SwipeRefreshLayout只能容纳一个直接子代的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!