ViewPager的使用

2026/4/23 9:24:37

@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分别是用来完成文本信息和图片的切换功能的。 可以支持包含动画效果的切换操作。

先来看文本切换功能。

通过程序对文本切换器进行初始化,并设置里面的TextView,同时要准备好多个页面的文本。

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)页


ViewPager的使用.doc 将本文的Word文档下载到电脑
搜索更多关于: ViewPager的使用 的文档
相关推荐
相关阅读
× 游客快捷下载通道(下载后可以自由复制和排版)

下载本文档需要支付 10

支付方式:

开通VIP包月会员 特价:29元/月

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信:xuecool-com QQ:370150219