最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

android?viewflipper實現(xiàn)左右滑動切換顯示圖片

 更新時間:2022年05月18日 08:38:16   作者:a107494639  
這篇文章主要為大家詳細介紹了android?viewflipper實現(xiàn)左右滑動切換顯示圖片,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文實例為大家分享了android viewflipper實現(xiàn)左右滑動切換顯示圖片的具體代碼,供大家參考,具體內(nèi)容如下

1.首先定義四個動畫文件,表示當view切換的時候的顯示效果

in_leftright.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >
?
? ? <translate
? ? ? ? android:duration="500"
? ? ? ? android:fromXDelta="0"
? ? ? ? android:toXDelta="-100%p" />
?
</set>

in_rightleft.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >
?
? ? <translate
? ? ? ? android:duration="500"
? ? ? ? android:fromXDelta="100%p"
? ? ? ? android:toXDelta="0" />
?
</set>

out_leftright.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >
?
? ? <translate
? ? ? ? android:duration="500"
? ? ? ? android:fromXDelta="0"
? ? ? ? android:toXDelta="100%p" />
?
</set>

out_rightleft.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >
?
? ? <translate
? ? ? ? android:duration="500"
? ? ? ? android:fromXDelta="0"
? ? ? ? android:toXDelta="-100%p" />
?
</set>

2.在main.xml中添加ViewFlipper控件,里面放三個LinearLayout,表示3個view

<?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" >
?
? ? <ViewFlipper
? ? ? ? android:id="@+id/viewFlipper"
? ? ? ? android:layout_width="match_parent"
? ? ? ? android:layout_height="match_parent" >
?
? ? ? ? <!-- first page -->
?
? ? ? ? <LinearLayout
? ? ? ? ? ? android:layout_width="match_parent"
? ? ? ? ? ? android:layout_height="match_parent"
? ? ? ? ? ? android:gravity="center" >
?
? ? ? ? ? ? <ImageView
? ? ? ? ? ? ? ? android:layout_width="wrap_content"
? ? ? ? ? ? ? ? android:layout_height="wrap_content"
? ? ? ? ? ? ? ? android:layout_gravity="center"
? ? ? ? ? ? ? ? android:src="@drawable/a001" />
? ? ? ? </LinearLayout>
?
? ? ? ? <!-- second page -->
?
? ? ? ? <LinearLayout
? ? ? ? ? ? android:layout_width="match_parent"
? ? ? ? ? ? android:layout_height="match_parent"
? ? ? ? ? ? android:gravity="center" >
?
? ? ? ? ? ? <ImageView
? ? ? ? ? ? ? ? android:layout_width="wrap_content"
? ? ? ? ? ? ? ? android:layout_height="wrap_content"
? ? ? ? ? ? ? ? android:layout_gravity="center"
? ? ? ? ? ? ? ? android:src="@drawable/a002" />
? ? ? ? </LinearLayout>
?
? ? ? ? <!-- third page -->
?
? ? ? ? <LinearLayout
? ? ? ? ? ? android:layout_width="match_parent"
? ? ? ? ? ? android:layout_height="match_parent"
? ? ? ? ? ? android:gravity="center" >
?
? ? ? ? ? ? <ImageView
? ? ? ? ? ? ? ? android:layout_width="wrap_content"
? ? ? ? ? ? ? ? android:layout_height="wrap_content"
? ? ? ? ? ? ? ? android:layout_gravity="center"
? ? ? ? ? ? ? ? android:src="@drawable/a003" />
? ? ? ? </LinearLayout>
?
? ? </ViewFlipper>
?
</LinearLayout>

3.最后在activity里的onTouchEvent事件中,來判斷是往哪個方向移動

package org.example.viewflipper;
?
import android.app.Activity;
import android.os.Bundle;
import android.view.MotionEvent;
import android.widget.ViewFlipper;
?
public class ViewFlipperActivity extends Activity {
?
? ? private ViewFlipper viewFlipper = null;
?
? ? float startX;
?
? ? @Override
? ? public void onCreate(Bundle savedInstanceState) {
? ? ? ? super.onCreate(savedInstanceState);
? ? ? ? setContentView(R.layout.main);
? ? ? ? // init widget
? ? ? ? viewFlipper = (ViewFlipper) findViewById(R.id.viewFlipper);
? ? }
?
? ? @Override
? ? public boolean onTouchEvent(MotionEvent event) {
? ? ? ? switch (event.getAction()) {
? ? ? ? case MotionEvent.ACTION_DOWN:
? ? ? ? ? ? startX = event.getX();
? ? ? ? ? ? break;
? ? ? ? case MotionEvent.ACTION_UP:
? ? ? ? ? ? if (event.getX() > startX) {// flip to right
? ? ? ? ? ? ? ? viewFlipper.setInAnimation(this, R.anim.in_leftright);
? ? ? ? ? ? ? ? viewFlipper.setOutAnimation(this, R.anim.out_leftright);
? ? ? ? ? ? ? ? viewFlipper.showNext();
? ? ? ? ? ? } else {// flip to left
? ? ? ? ? ? ? ? viewFlipper.setInAnimation(this, R.anim.in_rightleft);
? ? ? ? ? ? ? ? viewFlipper.setOutAnimation(this, R.anim.out_rightleft);
? ? ? ? ? ? ? ? viewFlipper.showPrevious();
? ? ? ? ? ? }
?
? ? ? ? }
? ? ? ? return super.onTouchEvent(event);
? ? }
}

以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。

相關文章

  • android仿知乎標題欄隨ScrollView滾動變色

    android仿知乎標題欄隨ScrollView滾動變色

    這篇文章主要為大家詳細介紹了android仿知乎標題欄隨ScrollView滾動變色,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2018-06-06
  • Android實現(xiàn)圓形圖片小工具

    Android實現(xiàn)圓形圖片小工具

    這篇文章主要為大家詳細介紹了Android實現(xiàn)圓形圖片小工具,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2022-09-09
  • Android實現(xiàn)ListView分頁加載數(shù)據(jù)

    Android實現(xiàn)ListView分頁加載數(shù)據(jù)

    這篇文章主要為大家詳細介紹了Android實現(xiàn)ListView分頁加載數(shù)據(jù),文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2021-11-11
  • Android實現(xiàn)手繪功能

    Android實現(xiàn)手繪功能

    這篇文章主要為大家詳細介紹了Android實現(xiàn)手繪功能,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2020-05-05
  • 打飛機游戲終極BOSS Android實戰(zhàn)打飛機游戲完結(jié)篇

    打飛機游戲終極BOSS Android實戰(zhàn)打飛機游戲完結(jié)篇

    打飛機游戲終極BOSS,Android實戰(zhàn)打飛機游戲完結(jié)篇,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2016-07-07
  • Android編程實現(xiàn)動態(tài)支持多語言的方法

    Android編程實現(xiàn)動態(tài)支持多語言的方法

    這篇文章主要介紹了Android編程實現(xiàn)動態(tài)支持多語言的方法,涉及Android資源、控件及屬性相關操作技巧,需要的朋友可以參考下
    2017-06-06
  • mac系統(tǒng)下載、安裝、使用Java8教程

    mac系統(tǒng)下載、安裝、使用Java8教程

    這篇文章主要介紹了在Mac OS上如何下載安裝Java8以及使用java8的基本方法,包括查看所安裝Java版本的方法,需要的朋友可以參考下
    2017-10-10
  • Android Handler機制詳解原理

    Android Handler機制詳解原理

    Handler主要用于異步消息的處理:當發(fā)出一個消息之后,首先進入一個消息隊列,發(fā)送消息的函數(shù)即刻返回,而另外一個部分在消息隊列中逐一將消息取出,然后對消息進行處理,也就是發(fā)送消息和接收消息不是同步的處理。 這種機制通常用來處理相對耗時比較長的操作
    2021-11-11
  • 關于Android中ListView嵌套GridView的問題

    關于Android中ListView嵌套GridView的問題

    在Android開發(fā)的過程中可能需要用到listview嵌套gridview的場景,但是在嵌套過程中也許會遇到問題,我們下面一起來看看是什么問題以及如何解決。
    2016-08-08
  • Android 手動獲取判斷處理權(quán)限

    Android 手動獲取判斷處理權(quán)限

    本篇文章主要介紹了Android手動獲取判斷處理權(quán)限的方法,具有很好的參考價值。下面跟著小編一起來看下吧
    2017-05-05

最新評論

隆林| 九寨沟县| 辰溪县| 林西县| 灵武市| 河西区| 香港| 虞城县| 西乌珠穆沁旗| 灌阳县| 宁化县| 虞城县| 安顺市| 托克托县| 呼伦贝尔市| 桐庐县| 青海省| 揭东县| 大丰市| 措勤县| 定兴县| 淮阳县| 奉节县| 沧源| 东至县| 卢湾区| 宾阳县| 诏安县| 望奎县| 沙雅县| 象州县| 晋州市| 元阳县| 桂阳县| 垣曲县| 太原市| 建瓯市| 武山县| 张家口市| 十堰市| 乌鲁木齐县|