提问者:小点点

SwipeRe新布局不工作


我正在使用支持库中的< code > SwipeRefreshListener 。我从我的< code>AsyncTask的< code>onPreExecute和< code>onPostExecute中调用< code>setRefresh。然而,什么都没有改变,没有动画。我错过了什么吗?为了让它正常工作,我需要设置某些设置参数吗?


共2个答案

匿名用户

这对我有用,在这里查看更多:http://antonioleiva.com/swiperefreshlayout/

SwipeRefreshLayout:您只需要用这个新布局来装饰可滑动内容(可能是整个布局)的布局。此视图必须是可滚动的,如ScrollView或ListView。举个简单的例子:

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

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

        <TextView
            android:text="@string/hello_world"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="16dp"
            android:gravity="center"/>
    </ScrollView>

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

代码我们只需要获取布局,并分配一些颜色和侦听器。刷新侦听器是一个后延迟处理程序。

 @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        swipeLayout = (SwipeRefreshLayout) findViewById(R.id.swipe_container);
        swipeLayout.setOnRefreshListener(this);
        swipeLayout.setColorScheme(android.R.color.holo_blue_bright, 
                android.R.color.holo_green_light, 
                android.R.color.holo_orange_light, 
                android.R.color.holo_red_light);
    }


    @Override public void onRefresh() {
        new Handler().postDelayed(new Runnable() {
            @Override public void run() {
                swipeLayout.setRefreshing(false);
            }
        }, 5000);
    }

匿名用户

//请检查这个答案,它会帮助我://SwipeRefreshLayout setRefreshing()最初不显示指示符//尤其是这个

  mSwipeRefreshLayout.post(new Runnable() {
    @Override
    public void run() {
        mSwipeRefreshLayout.setRefreshing(true);
    } 
  });