【发布时间】:2015-06-20 17:12:39
【问题描述】:
我有一个SwipeRefreshLayout。如果用户没有流我想显示错误页面,否则RecyclerView。
RecyclerView 工作正常,但如果用户没有流式传输,则不会显示错误页面。
这是我的代码
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/swipeRefreshLayout"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerview_stream"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/feed_item_padding_topbottom"
android:paddingTop="@dimen/feed_item_padding_topbottom"
android:scrollbars="vertical" />
<LinearLayout
android:id="@+id/error_page"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center"
android:gravity="center"
android:orientation="vertical" >
<ImageView
android:layout_width="@dimen/no_found_width"
android:layout_height="@dimen/no_found_height"
android:layout_marginBottom="15dp"
android:src="@drawable/ic_no_found" />
<TextView
android:id="@+id/error_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="@string/not_found"
android:textSize="@dimen/error_page_textsize" />
</LinearLayout>
</android.support.v4.widget.SwipeRefreshLayout>
</LinearLayout>
【问题讨论】:
-
你有java代码吗?这种方式很难理解。另外我认为你应该使用
match_parent而不是fill_parent -
SwipeRefreshLayout只带一个孩子。将您的错误页面放在它之外的根布局中。还将您的根布局从LinearLayout更改为FrameLayout。
标签: android android-layout swiperefreshlayout