viewFlipper 之二
main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".Main" >
<ViewFlipper
android:id="@+id/viewFlipper1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true" >
<!-- 第一个页面 -->
<LinearLayout android:layout_width="fill_parent"
android:layout_height="fill_parent" android:gravity="center">
<ImageView android:layout_width="wrap_content"
android:layout_height="wrap_content" android:src="@drawable/a3" />
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="start1" />
</LinearLayout>
<!-- 第二个页面 -->
<LinearLayout android:layout_width="fill_parent"
android:layout_height="fill_parent" android:gravity="center">
<ImageView android:layout_width="wrap_content"
android:layout_height="wrap_content" android:src="@drawable/a4"
android:gravity="center" />
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="start2" />
</LinearLayout>
<!-- 第三个页面 -->
<LinearLayout android:layout_width="fill_parent"
android:layout_height="fill_parent" android:gravity="center">
<ImageView android:layout_width="wrap_content"
android:layout_height="wrap_content" android:src="@drawable/a5"
android:gravity="center" />
<Button
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="start3" />
</LinearLayout>
<!-- 第四个页面 -->
<LinearLayout android:layout_width="fill_parent"
android:layout_height="fill_parent" android:gravity="center">
<ImageView android:layout_width="wrap_content"
android:layout_height="wrap_content" android:src="@drawable/a6"
android:gravity="center" />
<Button
android:id="@+id/button4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="start4" />
</LinearLayout>
</ViewFlipper>
</RelativeLayout>
Main.java
package com.example.myflipper;
import android.os.Bundle;
import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Intent;
import android.view.GestureDetector;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.ViewFlipper;
public class Main extends Activity {
NotificationManager mManager;
Notification mNotification;
private ViewFlipper viewFlipper;
private GestureDetector detector; // 手势检测
Animation leftInAnimation;
Animation leftOutAnimation;
Animation rightInAnimation;
Animation rightOutAnimation;
Button btn1, btn2, btn3, btn4;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.main);
btn1 = (Button) findViewById(R.id.button1);
btn2 = (Button) findViewById(R.id.button2);
btn3 = (Button) findViewById(R.id.button3);
btn4 = (Button) findViewById(R.id.button4);
mManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
mNotification = new Notification();
mNotification.icon = R.drawable.a2;
mNotification.when = System.currentTimeMillis();
OnClickListener myClick = new View.OnClickListener() {
@Override
public void onClick(View v) {
String btext = "";
switch (v.getId()) {
case R.id.button1:
btext = "你点了Button1";
break;
case R.id.button2:
btext = "你点了Button2";
break;
case R.id.button3:
btext = "你点了Button3";
break;
case R.id.button4:
btext = "你点了Button4";
break;
}
// TODO Auto-generated method stub
mNotification.tickerText = btext;
mNotification.flags = Notification.FLAG_AUTO_CANCEL;
Intent intent = new Intent(Main.this,Notice.class);
PendingIntent pIntent=PendingIntent.getActivity(Main.this, 0, intent, 0);
mNotification.setLatestEventInfo(getApplicationContext(), "小心正文", btext,pIntent );
mManager.notify(1, mNotification);
}
};
btn1.setOnClickListener(myClick);
btn2.setOnClickListener(myClick);
btn4.setOnClickListener(myClick);
btn3.setOnClickListener(myClick);
viewFlipper = (ViewFlipper) findViewById(R.id.viewFlipper1);
detector = new GestureDetector(this,
new GestureDetector.OnGestureListener() {
@Override
public boolean onSingleTapUp(
MotionEvent e) {
// TODO Auto-generated method
// stub
return false;
}
@Override
public void onShowPress(MotionEvent e) {
// TODO Auto-generated method
// stub
}
@Override
public boolean onScroll(MotionEvent e1,
MotionEvent e2,
float distanceX,
float distanceY) {
// TODO Auto-generated method
// stub
return false;
}
@Override
public void onLongPress(MotionEvent e) {
// TODO Auto-generated method
// stub
}
@Override
public boolean onFling(MotionEvent e1,
MotionEvent e2,
float velocityX,
float velocityY) {
if (e1.getX() - e2.getX() > 120) {
viewFlipper.setInAnimation(leftInAnimation);
viewFlipper.setOutAnimation(leftOutAnimation);
viewFlipper.showNext();// 向右滑动
return true;
} else if (e1.getX()
- e2.getY() < -120) {
viewFlipper.setInAnimation(rightInAnimation);
viewFlipper.setOutAnimation(rightOutAnimation);
viewFlipper.showPrevious();// 向左滑动
return true;
}
return false;
}
@Override
public boolean onDown(MotionEvent e) {
// TODO Auto-generated method
// stub
return false;
}
});
// 动画效果
leftInAnimation = AnimationUtils.loadAnimation(this,
R.layout.left_in);
leftOutAnimation = AnimationUtils.loadAnimation(this,
R.layout.left_out);
rightInAnimation = AnimationUtils.loadAnimation(this,
R.layout.right_in);
rightOutAnimation = AnimationUtils.loadAnimation(this,
R.layout.right_out);
}
@Override
public boolean onTouchEvent(MotionEvent event) {
return this.detector.onTouchEvent(event); // touch事件交给手势处理。
}
}
notice.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".Notice" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" />
</RelativeLayout>
Notice.java
package com.example.myflipper;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
public class Notice extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.notice);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is
// present.
getMenuInflater().inflate(R.menu.notice, menu);
return true;
}
}
动画配置文件
left_in.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:fromXDelta="100%p"
android:toXDelta="0"
android:duration="600"
/>
<alpha
android:fromAlpha="0.1"
android:toAlpha="1.0"
android:duration="600"
/>
</set>
left_out.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:fromXDelta="0"
android:toXDelta="-100%p"
android:duration="600"
/>
<alpha
android:fromAlpha="1.0"
android:toAlpha="0.1"
android:duration="600"
/>
</set>
right_in.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:fromXDelta="-100%p"
android:toXDelta="0"
android:duration="600"
/>
<alpha
android:fromAlpha="0.1"
android:toAlpha="1.0"
android:duration="600"
/>
</set>
right_out.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:fromXDelta="0"
android:toXDelta="100%p"
android:duration="600"
/>
<alpha
android:fromAlpha="1.0"
android:toAlpha="0.1"
android:duration="600"
/>
</set>
viewFlipper 之二的更多相关文章
- 【Android 复习】:Android之ViewFlipper(二)
通过手势移动屏幕 上面是通过屏幕上的按钮来在屏幕间切换的,这看起来多少有点不符合Android的风格,如果要是能通过手势的左右滑动来实现屏幕的切换就比较优雅了. 通过android.view.Gest ...
- 学习Jammendo代码的心路历程(二)ViewFlipper数据的填充
打开Jammendo进入到首页之后,会看到这样一个界面.可以看到下左效果,我们可以看到,他是上部分的ViewFlipper模块和下半部分的listview模块构成的,今天就简单的说一下Jammendo ...
- <Android 基础(三十二)> ViewFlipper
简介 View Flipper,是ViewAnimator的子类,而ViewAnimator又是继承自FrameLayout,而FrameLayout就是平时基本上只显示一个子视图的布局,由于Fram ...
- 二、Android应用的界面编程(七)ViewAnimator及其子类[ ViewSwitcher、ImageSwitcher、TextSwitcher、ViewFlipper ]
ViewAnimator是一个基类,它继承了FrameLayout.因此它表现出FrameLayout的特征,可以将多个View组“叠”在一起. ViewAnimator可以在View切换时表现出动画 ...
- Android中使用ViewFlipper实现屏幕页面切换(关于坐标轴的问题已补充更改)
屏幕切换指的是在同一个Activity内屏幕间的切换,ViewFlipper继承了Framelayout类,ViewAnimator类的作用是为FrameLayout里面的View切换提供动画效果.如 ...
- Android成长日记-使用ViewFlipper实现屏幕切换动画效果
(一) ViewFlipper介绍 Android系统自带的一个多页面管理控件,它可以实现子界面的自动切换 (二) 为ViewFlipper加入View 1. 静态导入:在Layout布局文件中直接导 ...
- Android 滑动效果入门篇(一)—— ViewFlipper
ViewFilpper 是Android官方提供的一个View容器类,继承于ViewAnimator类,用于实现页面切换,也可以设定时间间隔,让它自动播放.又ViewAnimator继承至于Frame ...
- (转)【移动开发】Android中三种超实用的滑屏方式汇总(ViewPager、ViewFlipper、ViewFlow)
转自: http://smallwoniu.blog.51cto.com/3911954/1308959 现如今主流的Android应用中,都少不了左右滑动滚屏这项功能,(貌似现在好多人使用智能机都习 ...
- Android高手进阶教程(二十八)之---Android ViewPager控件的使用(基于ViewPager的横向相册)!!!
分类: Android高手进阶 Android基础教程 2012-09-14 18:10 29759人阅读 评论(35) 收藏 举报 android相册layoutobjectclassloade ...
随机推荐
- 【BZOJ】1616: [Usaco2008 Mar]Cow Travelling游荡的奶牛(dp/-bfs)
http://www.lydsy.com/JudgeOnline/problem.php?id=1616 我觉得bfs是可过的,但是交bfs上去是wa? 然后没办法看dp,原来这bfs能和dp联系在一 ...
- BT下载会损害硬盘吗
简而言之,这个问题是否存在,取决于网络带宽的发展速度与硬件性能的发展速度.如果硬件发展的速度快, 网络带宽速度发展慢,那么对大多数人而言,当前的硬件在慢速的带宽下载BT不会造成任何的硬盘损坏. ...
- bootstrap基础学习七篇
bootstrap图片 Bootstrap 提供了三个可对图片应用简单样式的 class: .img-rounded:添加 border-radius:6px 来获得图片圆角. .img-circle ...
- adb server is out of date.killing的解决办法
当把手机连接到电脑端口运行adb程序调试时,出现了下面这样的情况: 分析:出错的原因是adb的端口被其他程序的进程占领了,所以要做的就是找到并kill该进程. 工具/原料 cmd.exe. ...
- js 文件上传进度条
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- 性能测试工具LoadRunner中进程运行和线程运行区别
loadrunner controller将使用驱动程序mmdrv运行Vuser.用户可以在controller的run-time setting中选择Vuser的运行方式, 是多进程方式or多线程方 ...
- Loadrunner如何遍历一个页面中的url并进行访问?
最近在网上到一个关于loadrunner遍历一个页面中的url并进行访问的脚本,就把它用我们自己的项目实践了一下,发现有一点不完善. 原始版本: Action(){char temp[64];int ...
- LED音乐频谱之概述
点击打开链接 转载请注明出处:http://blog.csdn.net/ruoyunliufeng/article/details/37929733 这个LED音乐频谱是我在学51单片机的 ...
- Spring_day02--课程安排_Spring的bean管理(注解)(注解创建对象/注入属性、配置文件和注解混合使用)
Spring_day02 上节内容回顾 今天内容介绍 Spring的bean管理(注解) 注解介绍 Spring注解开发准备 注解创建对象 注解注入属性 配置文件和注解混合使用 AOP概念 AOP原理 ...
- 剑指 offer set 20 打印出和为 s 的连续正序序列
题目 100 可以由 9~16, 或者 18 ~ 22 组成 思路 1. 与 Leetcode Container With Most Water 有些类似, 依然是平移题目. 但这道更加复杂 2. ...