2015-12-18 164 views
1

我有两个textviews和一个浮动的操作按钮和一个ListView。 目前我能够使用swiperefreshlayout的列表视图,但我想它的时候我刷卡从活动的自上而下,列表视图应后台更新使用全视图即。 任何人都可以帮助我。 这是我当前的xml文件。Android的刷卡刷新布局问题

<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> 

回答

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(); 
} 
+0

我想你的解决方案,但是当我们滑下出现圆形的东西是不可见的,所以你有什么想法为什么是这样? –

0
<?xml version="1.0" encoding="utf-8"?> 
<android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:fab="http://schemas.android.com/apk/res-auto" 
    android:id="@+id/swipe_container" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" > 

    <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" /> 

    <ListView 
     android:id="@+id/view_tickets_activity_list_view_tickets" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/view_tickets_activity_floating_btn_add_ticket" 
     android:layout_marginTop="15dp" /> 

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

我想你的解决方案,但是当我们滑下出现圆形的东西是不可见的,所以你有任何想法,为什么会这样呢? –

+0

必须声明布局“mSwipeLayout =(SwipeRefreshLayout)rootview.findViewById(R.id.swipe_container); mSwipeLayout.setOnRefreshListener(本); mSwipeLayout.setColorSchemeResources(android.R.color.holo_blue_bright,android.R.color.holo_green_light, \t \t \t \t android.R.color.holo_orange_light,android.R.color.holo_red_light); \t' –

+0

没有,依然没能达到要求的行为。 –

0

你不必像这样的ListView创建布局,你有为前。添加TextViews到标题的ListView,造成RelativeLayout的不可滚动,这就是为什么你不能有swipeToRefresh它