Android使用ViewPager实现左右切换02(转)
来源:互联网 发布:网络写作集剧本编写 编辑:程序博客网 时间:2024/06/05 18:05
临时转载
public class Welcome extends Activity implements OnGestureListener { private GestureDetector detector; private ViewFlipper flipper; private Button button; ImageView []iamges=new ImageView[4]; int i = 0; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.layoutwelcome); iamges[0]=(ImageView) findViewById(R.id.imageview1); iamges[1]=(ImageView) findViewById(R.id.imageview2); iamges[2]=(ImageView) findViewById(R.id.imageview3); iamges[3]=(ImageView) findViewById(R.id.imageview4); detector = new GestureDetector(this); flipper = (ViewFlipper) this.findViewById(R.id.ViewFlipper1); flipper.addView(addImageView(R.drawable.png1o)); flipper.addView(addImageView(R.drawable.png2o)); flipper.addView(addImageView(R.drawable.png3o)); flipper.addView(addView()); } private View addImageView(int id) { ImageView iv = new ImageView(this); iv.setImageResource(id); return iv; } @Override public boolean onTouchEvent(MotionEvent event) { // TODO Auto-generated method stub return this.detector.onTouchEvent(event); } private View addView() { LayoutInflater inflater = LayoutInflater.from(this); View view = inflater.inflate(R.layout.layoutwelcome2, null); button = (Button) view.findViewById(R.id.button); button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // Intent intent = new // Intent(getApplicationContext(),ActContent.class); // startActivity(intent); // finish(); Toast.makeText(Welcome.this, "Clicked", 2000).show(); } }); return view; } @Override public boolean onDown(MotionEvent e) { // TODO Auto-generated method stub return false; } @Override public void onShowPress(MotionEvent e) { // TODO Auto-generated method stub } @Override public boolean onSingleTapUp(MotionEvent e) { // TODO Auto-generated method stub return false; } @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) { System.out.println("in------------>>>>>>>"); if (e1.getX() - e2.getX() > 120) { if (i < 3) { i++; setImage(i); this.flipper.setInAnimation(AnimationUtils.loadAnimation(this, R.anim.animation_right_in)); this.flipper.setOutAnimation(AnimationUtils.loadAnimation(this, R.anim.animation_left_out)); this.flipper.showNext(); } return true; } else if (e1.getX() - e2.getX() < -120) { if (i > 0) { i--; setImage(i); this.flipper.setInAnimation(AnimationUtils.loadAnimation(this, R.anim.animation_left_in)); this.flipper.setOutAnimation(AnimationUtils.loadAnimation(this, R.anim.animation_right_out)); this.flipper.showPrevious(); } return true; } return false; } void setImage(int i) { for(int j=0;j<4;j++) { if(j!=i) iamges[j].setImageResource(R.drawable.xiao); else iamges[j].setImageResource(R.drawable.da); } }}
主要布局
<?xml version="1.0" encoding="utf-8"?><FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <ViewFlipper android:id="@+id/ViewFlipper1" android:layout_width="fill_parent" android:layout_height="fill_parent"> </ViewFlipper> <LinearLayout android:orientation="horizontal" android:layout_width="wrap_content" android:layout_gravity="bottom|center_horizontal" android:layout_height="wrap_content" > <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/da" android:id="@+id/imageview1" /> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/xiao" android:id="@+id/imageview2" /> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/xiao" android:id="@+id/imageview3" /> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/xiao" android:id="@+id/imageview4" /> </LinearLayout></FrameLayout>
次要布局
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" ><Button android:id="@+id/button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginBottom="45dp" android:text="进入程序" android:textColor="#3E3E3E" android:layout_gravity="center_horizontal" /></LinearLayout>
由于工作原因,无法下载代码。因此贴出代码仅供自己学习。学习结束整理分析或者删除博文。
0 0
- Android使用ViewPager实现左右切换02(转)
- Android使用ViewPager实现左右切换(转)
- Android:使用ViewPager实现左右滑动切换图片 (简单版)
- Android:使用ViewPager实现左右滑动切换图片 (简单版)
- android ViewPager实现页面左右切换效果
- Android:使用ViewPager实现左右滑动切换图片(图上有点点)
- ViewPager实现左右切换
- Android实现左右滑动指引效果(使用ViewPager)
- Android实现左右滑动指引效果(使用ViewPager)
- android 使用ViewPager实现左右滑动
- Android使用ViewPager实现左右滑动效果
- android 使用ViewPager实现左右滑动
- Android通过ViewPager实现左右滑动切换图片
- Android中viewPager实现的屏幕左右切换(入门篇)
- Android 实现多页界面左右滑动切换效果之入门+进阶 (ViewPager+PagerAdapter)
- ViewPager的使用(实现微信左右切换页卡功能)
- ViewPager实现左右两个屏幕的切换
- ViewPager-实现左右两个屏幕的切换
- 用数组作为函数返回值
- Android系统截屏功能提取
- Windows 7系统64位下vpn连接789错误解决方法
- hdu 5078
- 作业 5.19
- Android使用ViewPager实现左右切换02(转)
- poj1258 Agri-Net +hdu 1233 还是畅通工程 (最小生成树Prime算法)
- Django学习笔记(第四节)模板
- 仿《文明》游戏制作日志3
- 让WCF只需要配置服务地址
- 漫漫长日,匆匆十年:YC掌门人 Sam Altman 分享36条人生经验
- uva 10534题解(lis)
- 玩命牛的成长记录(十五)——编码前准备
- 本地图片的异步加载