其他分享
首页 > 其他分享> > android – 使用嵌套RelativeLayout的SwipeRefreshLayout

android – 使用嵌套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中的附加相对布局

谢谢

解决方法:

尝试将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>

It will easily work and on changing ListView content you could also change TextView text on SwipeRefresh Listener.

标签:android,listview,relativelayout,swiperefreshlayout
来源: https://codeday.me/bug/20190624/1276713.html