开始使用SwipeRefreshLayout中容纳一个ListView的时候进行刷新不会有任何问题,但是当我把SwipeRefreshLayout中的子元素换成TextView后问题出现了,刷新的时候动画显示居然不完整!刚跳出来就结束了。

查询文档,文档中有这么一句

If an activity wishes to show just the progress animation, it should call setRefreshing(true)
不幸的是问题依旧。


后来参看了 匆忙拥挤repeat 的代码 将ScrollView作为SwipeRefreshLayout的子元素,将TextView添加到ScrollView中,问题圆满解决。

附上测试源码


布局文件 activity_main.xml

                                    

MainActivity.java

package weather.ricearmy.com.weatherforcast;import android.os.Handler;import android.support.v4.widget.SwipeRefreshLayout;import android.support.v7.app.ActionBarActivity;import android.os.Bundle;import android.view.Menu;import android.view.MenuItem;import android.widget.ArrayAdapter;import android.widget.ListView;import android.widget.TextView;import java.util.ArrayList;import java.util.Arrays;import java.util.List;public class MainActivity extends ActionBarActivity implements SwipeRefreshLayout.OnRefreshListener {    private static final int REFRESH_COMPLETE = 0X110;    private SwipeRefreshLayout mSwipeLayout;    private TextView tvText;    private Handler mHandler = new Handler()    {        public void handleMessage(android.os.Message msg)        {            switch (msg.what)            {                case REFRESH_COMPLETE: {                    String text = tvText.getText().toString();                    tvText.setText(text+" helloWorld");                    mSwipeLayout.setRefreshing(false);                }                break;            }        };    };    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_main);        tvText = (TextView)findViewById(R.id.tvText);        mSwipeLayout = (SwipeRefreshLayout) findViewById(R.id.id_swipe_ly);        mSwipeLayout.setOnRefreshListener(this);        mSwipeLayout.setColorSchemeResources(android.R.color.holo_blue_bright, android.R.color.holo_green_light);    }    @Override    public boolean onCreateOptionsMenu(Menu menu) {        // Inflate the menu; this adds items to the action bar if it is present.        getMenuInflater().inflate(R.menu.menu_main, menu);        return true;    }    @Override    public boolean onOptionsItemSelected(MenuItem item) {        // Handle action bar item clicks here. The action bar will        // automatically handle clicks on the Home/Up button, so long        // as you specify a parent activity in AndroidManifest.xml.        int id = item.getItemId();        //noinspection SimplifiableIfStatement        if (id == R.id.action_settings) {            return true;        }        return super.onOptionsItemSelected(item);    }    @Override    public void onRefresh() {        mHandler.sendEmptyMessageDelayed(REFRESH_COMPLETE, 2000);    }}



更多相关文章

  1. Androd学习笔记—— Android刷新本地相册
  2. Android中RelativeLayout的使用-----------转载下----以免忘记.
  3. 在Eclipse中用javadoc给android工程库文件生成API说明文档
  4. TCPDUMP for Android(抓TCP数据包工具)
  5. Android(安卓)2.2 r1 API中文文档—— Toast
  6. Android(安卓)五种布局模式
  7. Cocos2d-x的Android配置以及相关参考文档
  8. Android开发之布局简介(1)
  9. android 开源项目PullToRefresh

随机推荐

  1. 如何将ADT(eclipse)开发工具锁定到LaucherP
  2. adapter 阴影问题
  3. Android(安卓)Activity中启动另一应用程
  4. radio button修改样式
  5. 自定义VIEW③Canvas
  6. 转Launcher研究之AndroidManifest.xml分
  7. Android中的Menu点滴记录
  8. 《Android取证实战:调查、分析与移动安全
  9. Android(安卓)Retrofit OkHttp添加Interc
  10. Android源码 半小时下完Android系统源码