android 动画(5)ViewSwitcher
2016-06-30 08:32
477 查看
[b]ViewSwitcher 的作用简单来说就是:在两个视图间转换时显示动画 [/b]
[b]它的两个子类应该很熟悉,[/b]
[b] ImageSwitcher:转换图片时增加动画效果; [/b]
[b] TextSwitcher: 转换文字时增加动画效果; [/b]
[b]布局:[/b]
界面的切换
[b]布局:[/b]
[b]它的两个子类应该很熟悉,[/b]
[b] ImageSwitcher:转换图片时增加动画效果; [/b]
[b] TextSwitcher: 转换文字时增加动画效果; [/b]
[b]布局:[/b]
<?xml version="1.0" encoding="utf-8"?> [b]<ViewSwitcher [/b]xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/view_switcher" android:layout_width="match_parent" android:inAnimation="@android:anim/slide_in_left" android:outAnimation="@android:anim/slide_out_right" android:layout_height="match_parent" > <!-- 第一个视图 --> <RelativeLayout android:layout_width="match_parent" android:layout_height="match_parent"> <Button android:id="@+id/ne" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerVertical="true" android:text="下一张"/> </RelativeLayout> <!-- 第二个视图 --> <RelativeLayout android:layout_width="match_parent" android:layout_height="match_parent"> <Button android:id="@+id/up" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerVertical="true" android:text="上一张"/> <ImageView android:id="@+id/image" android:layout_toRightOf="@id/up" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerVertical="true" android:src="@drawable/ic_launcher"/> </RelativeLayout> </ViewSwitcher>
界面的切换
public class ViewSwitcherAct extends Activity{ private ViewSwitcher switcher; private Button upper,next; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.view_switcher); switcher = (ViewSwitcher) findViewById(R.id.view_switcher); upper = (Button) findViewById(R.id.up); next = (Button) findViewById(R.id.ne); //切换到第一个view switcher.setDisplayedChild(0); upper.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { switcher.showPrevious(); } }); next.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { switcher.showNext(); } }); } }
[b]布局:[/b]
相关文章推荐
- 安卓简单开发-安卓自带几种动画效果
- android 动画(4)自定义动画
- android编译
- Android中的责任链模式分析
- Android存储系统如何优化?
- android:layout_gravity和android:gravity
- android 动画(3)属性动画
- android高级工程师应该会的知识
- 基于Android系统Api封装常用工具类
- android 动画(2)帧动画
- 一个小白从零基础自学Android编程笔记之如何切换另一个活动(窗口)
- Android数据持久化存储
- Android开发小问题记录
- android Activity 四大启动模式探究
- 广播
- Android studio 配置retrolambda
- Android stadio butternife工具
- Android平台使用PocketSphinx做离线语音识别,小范围语音99%识别率
- pocketsphinxAdroid离线语音识别---入门
- Android自定义控件实现导航条IndicatorView