使用ViewSwitcher和ViewFlipper在不同布局中切换
xml布局:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ViewSwitcher
android:id="@+id/switcher"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inAnimation="@anim/slide_in_top"
android:outAnimation="@anim/slide_out_bottom" >
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:layout_width="fill_parent"
android:layout_height="100dp"
android:background="#123456"
android:text="11111111"
android:textSize="32sp" >
</TextView>
</RelativeLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:layout_width="fill_parent"
android:layout_height="100dp"
android:background="#FFFFFFFF"
android:text="22222222"
android:textSize="32sp" >
</TextView>
</RelativeLayout>
</ViewSwitcher>
<Button
android:id="@+id/prev"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="prev" />
<Button
android:id="@+id/next"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="next" />
</LinearLayout>
自定义的动画,也可以用系统自带的,在@android:anim/目录:
slide_in_top.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >
<translate
android:duration="2000"
android:fromYDelta="-100%p"
android:toYDelta="0" />
</set>
slide_in_bottom.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >
<translate
android:duration="2000"
android:fromYDelta="0"
android:toYDelta="100%p" />
</set>
Java代码:
package com.arnold.activity;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ViewSwitcher;
public class MainActivity extends Activity {
/** Called when the activity is first created. */
private ViewSwitcher mSwitcher;
private Button btn_prev, btn_next;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mSwitcher = (ViewSwitcher) findViewById(R.id.switcher);
mSwitcher.setDisplayedChild(0);
btn_next = (Button) findViewById(R.id.next);
btn_prev = (Button) findViewById(R.id.prev);
btn_next.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mSwitcher.showNext();
}
});
btn_prev.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mSwitcher.showPrevious();
}
});
}
}
注意:ViewSwitcher只可以在两种布局中切换,ViewFlipper可以应用多种布局,用法基本一样但后者多出几个方法:
isFlipping:用来判断View切换是否正在进行
setFilpInterval:设置View之间切换的时间间隔
startFlipping:使用上面设置的时间间隔来开始切换所有的View,切换会循环进行
stopFlipping:停止View切换
使用ViewSwitcher和ViewFlipper在不同布局中切换的更多相关文章
- 在布局中使用android.support.v4.app.Fragment的注意事项
1.Activity必须继承android.support.v4.app.FragmentActivity 2.fragment标签的name属性必须是完全限定包名,如下: <LinearLay ...
- DIV+CSS布局中主要CSS属性介绍
Float: Float属性是DIV+CSS布局中最基本也是最常用的属性,用于实现多列功能,我们知道<div>标签默认一行只能显示一个,而使用Float属性可以实现一行显示多个div的功能 ...
- 响应式web布局中iframe的自适应
困境 在响应式布局中,我们应该小心对待iframe元素,iframe元素的width和height属性设置了其宽度和高度,但是当包含块的宽度或高度小于iframe的宽度或高度时,会出现iframe元素 ...
- 在网页布局中合理使用inline formating context(IFC)
引子:给大家出一个小小的考题,如何使用css来实现类似下面的在指定区域内,内容自适应的垂直居中.
- Android 布局中 如何使控件居中
首先要分两种不同情况,在两种不同的布局方式下:LinearLayout 和RelativeLayout 1. LinearLayout a). android:layout_gravity=" ...
- CSS布局中的水平垂直居中
CSS布局中的水平垂直居中 各位好,先说两句题外话.今天是我开通博客园的博客第一天,虽然我申请博客园的账号已经有一年半了,但是由于各种原因迟迟没有开通自己的博客.今天非常有幸开通博客,在此也写一篇关于 ...
- CSS弹性盒模型flex在布局中的应用
× 目录 [1]元素居中 [2]两端对齐 [3]底端对齐[4]输入框按钮[5]等分布局[6]自适应布局[7]悬挂布局[8]全屏布局 前面的话 前面已经详细介绍过flex弹性盒模型的基本语法和兼容写法, ...
- 【转】在Android布局中使用include和merge标签
内容转自:http://fengweipeng1208.blog.163.com/blog/static/21277318020138229754135/ 在我们开发android布局时,经常会有很多 ...
- 几张图弄明白ios布局中的尺寸问题
背景 先说说逆向那事.各种曲折..各种技术过时,老老实实在啃看雪的帖子..更新会有的. 回正题,这里讨论的是在Masnory框架下的布局问题.像我这种游击队没师傅带,什么都得自己琢磨,一直没闹明白下面 ...
随机推荐
- .NET程序与CA对接一直提示重定向
最可能问题:应用程序服务器与CA服务器时间不同步 解决方法: 打开时间,选择internet时间,操作如图,在.net程序服务器 输入CA服务器的IP ,或者CA服务器输入 .net程序部署服务器的I ...
- Do less things
就这样,选择做更少的事情,我觉得挺好,至少能睡得很踏实,吃饭很香,也不会觉得难受! 就这样,节制自己的欲望,但是却能很平静,安安静静走自己的路,我觉得生活有希望,也有快乐! 早上,已经可以八点十分起床 ...
- http 302
404 not found500 internal server error 302临时重定向.指被访问的网页由于各种需求临时跳转到其它页面. yii若用户为游客状态,但controller中添加了权 ...
- windows在远程桌面连接中使用命令行参数
在此版本的 Windows 中,可以从搜索框("运行"对话框或命令行)启动远程桌面连接,而不是从「开始」菜单启动它. 从"运行"对话框启动远程桌面的步骤 依次单 ...
- 实现MySQL的Replication
实现MySQL的Replication 实现MySQL的Replication在MySQL 3.23.15版本之后,MySQL提供了数据库复制的功能,可以实现两个数据库实时同步,增强了MySQ ...
- 写给Node.js新手的7个小技巧
一些我更愿意在开始就知道东西 利用 Node.js 开发是一个非常有趣,和令人满足的过程, 他有3万多个模块可以选择使用,并且所有的模块可以非常容易的集成入现有的应用之中. 无论如何,对于一些刚开始使 ...
- rpm软件包
安装软件:rpm -i software.rpm卸载软件:rpm -e software升级形式安装:rpm -U software-new.rpmrpm支持通过http.ftp协议安装软件:rpm ...
- Oracle一些常用的查询命令总结(持续更新)
更新于:2015年1月28日 17:08:13 -------------------------表空间 --------------------------------------- ----- 查 ...
- Web Service 中返回DataSet结果的几种方法
Web Service 中返回DataSet结果的几种方法: 1)直接返回DataSet对象 特点:通常组件化的处理机制,不加任何修饰及处理: 优点:代码精减.易于处理,小数据量处理较快: ...
- 转载Mongondb
转自(http://blog.csdn.net/lchjustc/article/details/16988251) Mongodb调研 1. 调研目的 现在公司缺乏一个通用的key-value存 ...