Android(安卓)中SwipeRefreshLayout刷新动画不显示的问题
16lz
2021-01-26
开始使用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); }}
更多相关文章
- Androd学习笔记—— Android刷新本地相册
- Android中RelativeLayout的使用-----------转载下----以免忘记.
- 在Eclipse中用javadoc给android工程库文件生成API说明文档
- TCPDUMP for Android(抓TCP数据包工具)
- Android(安卓)2.2 r1 API中文文档—— Toast
- Android(安卓)五种布局模式
- Cocos2d-x的Android配置以及相关参考文档
- Android开发之布局简介(1)
- android 开源项目PullToRefresh