Android刷卡刷新布局问题

时间:2015-12-18 08:45:31

标签: android swiperefreshlayout

我有两个textview和一个浮动操作按钮,以及一个listview。 目前我可以使用swiperefreshlayout进行列表视图,但我希望它用于整个视图,即当我从活动顶部向下滑动时,列表视图应该在后台更新。 任何人都可以帮助我。 这是我当前的xml文件。

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

        <TextView android:id="@+id/view_tickets_activity_text_view_note"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp" />

        <TextView android:id="@+id/view_tickets_activity_text_view_customer_name"
            android:layout_width="220dp"
            android:layout_height="wrap_content"
            android:layout_alignLeft="@+id/view_tickets_activity_text_view_note"
            android:layout_below="@+id/view_tickets_activity_text_view_note"
            android:layout_marginTop="10dp" />

        <android.support.design.widget.FloatingActionButton android:id="@+id/view_tickets_activity_floating_btn_add_ticket"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" android:layout_alignParentRight="true"  android:layout_alignTop="@+id/view_tickets_activity_text_view_customer_name" />                             


        <android.support.v4.widget.SwipeRefreshLayout
            android:id="@+id/swipe"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_below="@+id/view_tickets_activity_floating_btn_add_ticket"
            android:layout_marginTop="15dp">

            <ListView
                android:id="@+id/view_tickets_activity_list_view_tickets"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" />

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

2 个答案:

答案 0 :(得分:1)

在整个布局上使用SwipeRefreshLayout

<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/swipe"
android:layout_height="match_parent"
android:layout_width="match_parent">

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

    <TextView
        android:id="@+id/view_tickets_activity_text_view_note"
        android:layout_height="wrap_content"
        android:layout_marginLeft="10dp"
        android:layout_width="wrap_content" />

    <TextView
        android:id="@+id/view_tickets_activity_text_view_customer_name"
        android:layout_alignLeft="@+id/view_tickets_activity_text_view_note"
        android:layout_below="@+id/view_tickets_activity_text_view_note"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        android:layout_width="220dp" />

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/view_tickets_activity_floating_btn_add_ticket"
        android:layout_alignParentRight="true"
        android:layout_alignTop="@+id/view_tickets_activity_text_view_customer_name"
        android:layout_height="wrap_content"
        android:layout_width="wrap_content" />

    <ListView
        android:id="@+id/view_tickets_activity_list_view_tickets"
        android:layout_below="@+id/view_tickets_activity_floating_btn_add_ticket"
        android:layout_height="wrap_content"
        android:layout_marginTop="15dp"
        android:layout_width="match_parent" />
</RelativeLayout>
</android.support.v4.widget.SwipeRefreshLayout>

并更新您的ListView

    @Override
public void onRefresh() {
    // Update Adapter for ListView here
    adapter.notifyDataSetChanged();
}

答案 1 :(得分:0)

您不必像这样使用ListView创建布局,您可以使用ex。将TextViews添加到ListView的标题中,导致RelativeLayout不可滚动,这就是为什么你不能使用swipeToRefresh

相关问题