SwipeRefreshLayout与嵌套的RelativeLayout

时间:2014-11-07 09:34:43

标签: android listview relativelayout swiperefreshlayout

您好我有以下布局

<android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/swipe_container"
android:layout_width="match_parent"
android:layout_height="match_parent" >

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
>

        <ListView
    android:id="@+id/list"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:divider="@color/list_divider"
    android:dividerHeight="1dp"
    android:listSelector="@drawable/list_row_selector"
    android:layout_below="@+id/coupons_header" />

<TextView
    android:id="@+id/header"
    android:layout_width="fill_parent"
    android:layout_height="40dp"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    android:gravity="center"
    android:orientation="vertical"
    android:text="Header" />

</RelativeLayout>

</android.support.v4.widget.SwipeRefreshLayout>

问题是当我向上滚动然后向下列表视图行为真的很奇怪查看以下屏幕http://sger.org/image/3D0Y1b0G1m3L

如何更正SwipeRefreshLayout内的附加相对布局

由于

1 个答案:

答案 0 :(得分:4)

尝试将android:clickable="true"添加到RelativeLayout,其中android:layout_below="@+id/coupons_header"。您的 coupons_header 丢失了。你也可以改变你的布局,如

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation ="vertical">

<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/swipe_container"
android:layout_width="match_parent"
android:layout_height="0dp" 
android:weight = "1">


    <ListView
    android:id="@+id/list"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:divider="@color/list_divider"
    android:dividerHeight="1dp"
    android:listSelector="@drawable/list_row_selector" />


</android.support.v4.widget.SwipeRefreshLayout>

<TextView
    android:id="@+id/header"
    android:layout_width="fill_parent"
    android:layout_height="40dp"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    android:gravity="center"
    android:orientation="vertical"
    android:text="Header" />

</LinearLayout>
  

它很容易使用,在更改ListView内容时,您还可以在 SwipeRefresh Listener 上更改TextView文本。