@Override protected void onDestroy() { if (player != null) { try { if (player.isPlaying()) { player.stop(); } player.release(); } catch (Exception e) { e.printStackTrace(); } } if (t != null) { flag = false; try { t.interrupt(); } catch (Exception e) { e.printStackTrace(); } } super.onDestroy(); }
第(13)页 共(30)页
}
3.2、TextSwitcher,ImageSwitcher(了解)
TextSwitcher和ImageSwitcher分别是用来完成文本信息和图片的切换功能的。 可以支持包含动画效果的切换操作。
先来看文本切换功能。
public class MainActivity extends Activity { private TextSwitcher switcher; private String[] allText = { \第一页的文本,封面\, \getAccessibleStateSet()获得此对象的状态。\, \覆盖:类 Component.AccessibleAWT\, \中的 getAccessibleStateSet返回:包含对象当前状态集合的 AccessibleStateSet 的实例另请参见:
第(14)页 共(30)页
AccessibleState\ }; // 当前显示的页数索引 private int nowIndex = 0; // 定义按下的位置坐标 private float startX; private long startTime; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Globals.init(this); // 设置所使用的布局界面 setContentView(R.layout.activity_main); // 取得switcher组件 switcher = (TextSwitcher) findViewById(R.id.switcher); // 设置一个建立TextView的工厂 switcher.setFactory(new ViewFactory() { @Override
第(15)页 共(30)页
public View makeView() { // 建立显示文本的TextView TextView text = new TextView(MainActivity.this); text.setTextSize(16); text.setTextColor(Color.BLACK); text.setBackgroundColor(Color.WHITE); text.setLayoutParams(new LayoutParams( LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); return text; } }); switcher.setText(allText[nowIndex]); // 可以设置切换时的动画效果 // 进入的动画,先使用系统提供的动画效果 // switcher.setInAnimation(AnimationUtils.loadAnimation(this, // android.R.anim.slide_in_left)); // 离开的动画 //
第(16)页 共(30)页

