日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 运维知识 > Android >内容正文

Android

Android ViewFlipper实现多个布局手势切换的效果

發(fā)布時間:2024/1/17 Android 21 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Android ViewFlipper实现多个布局手势切换的效果 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
這里用到了前面學(xué)過的 手勢效果,如果對手勢還是不很了解的話可以去看一下這篇文章 Android使用GestureDetector實現(xiàn)手勢滑動效果 先看一下布局文件 activity_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" tools:context=".MainActivity" ><ViewFlipper android:id="@+id/viewFlipper1" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_centerVertical="true" ><LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:background="#ff000000" android:orientation="vertical" > </LinearLayout><LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:background="#ffcccccc" android:orientation="vertical" > </LinearLayout><LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:background="#ffff6600" android:orientation="vertical" > </LinearLayout> </ViewFlipper></RelativeLayout> 布局文件很簡單,在ViewFlipper中包含了三個布局,全部用背景顏色區(qū)分。 再看一下MainActivity.java package com.example.viewflipper;import android.os.Bundle; import android.app.Activity; import android.view.GestureDetector; import android.view.GestureDetector.OnGestureListener; import android.view.Menu; import android.view.MotionEvent; import android.widget.Toast; import android.widget.ViewFlipper;public class MainActivity extends Activity implements OnGestureListener {private GestureDetector mGestureDetector; private ViewFlipper mViewFlipper = null;@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mGestureDetector = new GestureDetector(this, this); mViewFlipper = (ViewFlipper) findViewById(R.id.viewFlipper1); }@Override public boolean onTouchEvent(MotionEvent event) { // TODO Auto-generated method stub mGestureDetector.onTouchEvent(event); return super.onTouchEvent(event); }@Override public boolean onDown(MotionEvent arg0) { // TODO Auto-generated method stub // Toast.makeText(this, "onDown", Toast.LENGTH_SHORT).show(); return false; }@Override public boolean onFling(MotionEvent startEvent, MotionEvent endEvent, float velocityX, float velocityY) { // TODO Auto-generated method stub if (startEvent.getY() - endEvent.getY() > 100) { Toast.makeText(this, "手勢向上滑動", Toast.LENGTH_SHORT).show(); return true; } else if (startEvent.getY() - endEvent.getY() < -100) { Toast.makeText(this, "手勢向下滑動", Toast.LENGTH_SHORT).show(); return true; } else if (startEvent.getX() - endEvent.getX() > 100) { Toast.makeText(this, "手勢向左滑動", Toast.LENGTH_SHORT).show(); mViewFlipper.showNext(); return true; } else if (startEvent.getX() - endEvent.getX() < -100) { Toast.makeText(this, "手勢向右滑動", Toast.LENGTH_SHORT).show(); mViewFlipper.showPrevious(); return true; } return false; }@Override public void onLongPress(MotionEvent arg0) { // TODO Auto-generated method stub // Toast.makeText(this, "onLongPress ", Toast.LENGTH_SHORT).show(); }@Override public boolean onScroll(MotionEvent arg0, MotionEvent arg1, float arg2, float arg3) { // TODO Auto-generated method stub // Toast.makeText(this, "onScroll", Toast.LENGTH_SHORT).show(); return false; }@Override public void onShowPress(MotionEvent arg0) { // TODO Auto-generated method stub // Toast.makeText(this, "onShowPress", Toast.LENGTH_SHORT).show(); }@Override public boolean onSingleTapUp(MotionEvent arg0) { // TODO Auto-generated method stub // Toast.makeText(this, "onSingleTapUp", Toast.LENGTH_SHORT).show(); return false; }@Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.activity_main, menu); return true; }} 這樣就可以實現(xiàn)最簡單的切換效果了。

總結(jié)

以上是生活随笔為你收集整理的Android ViewFlipper实现多个布局手势切换的效果的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。