【发布时间】:2018-12-12 19:37:52
【问题描述】:
我想在滚动视图中显示一个 ListView。这似乎在添加 SwipeRefresh 布局之前有效。添加后,刷新工作,但我不能再滚动。
我相信问题出在 XML 代码上。请注意,如果我使用普通的 ScrollView,我可以同时执行这两项操作,但我无法向上滚动,因为 SwipeRefresh 已激活。
这是我的 XML 代码:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:fitsSystemWindows="true"
>
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/swipe_favorites"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="?attr/actionBarSize"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<LinearLayout
android:layout_height="match_parent"
android:layout_width="match_parent"
android:layout_marginBottom="60dp"
android:id="@+id/friends_scrollLayout"
android:layout_below="@id/friends_search">
<android.support.v4.widget.NestedScrollView
android:id="@+id/favorite_horeca_scrollview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
android:fillViewport="true"
android:scrollbars="none"
android:scrollingCache="true">
<LinearLayout
android:id="@+id/favorite_horeca_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ListView
android:id="@+id/favorite_horeca_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:dividerHeight="-1dp" />
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
</LinearLayout>
</android.support.v4.widget.SwipeRefreshLayout>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/empty"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#F5F7F8"
android:visibility="gone"
>
<ImageView
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_centerInParent="true"
android:layout_above="@id/empty_text"
android:layout_marginBottom="20dp"
android:gravity="center_vertical|center_horizontal"
android:src="@drawable/ic_logo_vert_rond"
/>
<TextView
android:id="@+id/empty_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="No Horecas added to your favorites."
android:gravity="center_horizontal|center_vertical"/>
</RelativeLayout>
【问题讨论】:
-
该布局中的两个
<LinearLayout>s 和<NestedScrollView>都是不必要的。只需将<ListView>直接放在<SwipeRefreshLayout>中即可。
标签: android xml scrollview swipe swiperefreshlayout