我正在使用 ListView
并在使用 SwipeRefresh
向下滑动时刷新它,到这里为止一切正常。当我尝试设置 TextView
时出现问题在 mListview.setEmptyView()
Refresh Icon
滑动时不显示。
貌似在TextView
下.但是,如果我不把它 TextView
在同一个 XML 上它工作正常,但我需要在列表为空时显示一条消息。 是什么导致了这种行为?
这是我使用的布局:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingLeft="@dimen/padding_light"
android:paddingRight="@dimen/padding_light">
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/swipeRefreshLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true">
<ListView
android:id="@+id/mListView"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</android.support.v4.widget.SwipeRefreshLayout>
<TextView
android:id="@+id/swipeToRefreshTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginBottom="15dp"
android:gravity="center_horizontal"
android:text="@string/msg_swipe_to_refresh"
android:visibility="gone" />
</RelativeLayout>
这是刷新监听器:
//Listeners
mSwipeRefresh.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
//Here I do some job
beaconScanSwipeRefresh.setRefreshing(false);
}
});
这里是我设置 ListView
适配器的地方和 onEmptyView:
//UI
mListLv = (ListView) view.findViewById(R.id.mListView);
mSwipeRefresh=(SwipeRefreshLayout)view.findViewById(R.id.swipeRefreshLayout);
swipeToRefreshTv = (TextView)view.findViewById(R.id.swipeToRefreshTextView);
//Set Adapter
mListLv.setAdapter(mBaseAdapter);
//Set Message when list is empty
mListLv.setEmptyView(swipeToRefreshTv);
我试图移动我的 TextView
里面<android.support.v4.widget.SwipeRefreshLayout
标签或在它们之上。结果还是一样。
最佳答案
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingLeft="@dimen/padding_light"
android:paddingRight="@dimen/padding_light">
<TextView
android:id="@+id/swipeToRefreshTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="@string/msg_swipe_to_refresh"
android:visibility="gone" />
<android.support.v4.widget.SwipeRefreshLayout
//below = swipeToRefreshTextView
android:id="@+id/swipeRefreshLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true">
<ListView
android:id="@+id/mListView"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</android.support.v4.widget.SwipeRefreshLayout>
</RelativeLayout>
请以这种方式更新您的布局并检查。
关于android - 滑动刷新图标显示不正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28106720/