【问题标题】:SwipeRefreshLayout not workingSwipeRefreshLayout 不起作用
【发布时间】:2014-07-20 21:43:01
【问题描述】:

我正在使用支持库中的SwipeRefreshListener。我从onPreExecuteonPostExecuteAsyncTask 打电话给setRefresh。但是,没有任何变化,没有动画。有什么我想念的吗?是否需要设置某些设置参数才能使其正常工作?

【问题讨论】:

    标签: android android-widget android-support-library


    【解决方案1】:

    这对我有用,在此处查看更多信息: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 仅作为可滑动视图的父级起作用,谢谢
    【解决方案2】:

    //请检查这个答案,它对我有帮助: //SwipeRefreshLayout setRefreshing() not showing indicator initially //尤其是这个

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-11-07
      • 1970-01-01
      • 1970-01-01
      • 2019-10-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多