欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

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

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

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

1.首先定義四個(gè)動(dòng)畫(huà)文件,表示當(dāng)view切換的時(shí)候的顯示效果

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控件,里面放三個(gè)LinearLayout,表示3個(gè)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事件中,來(lái)判斷是往哪個(gè)方向移動(dòng)

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);
? ? }
}

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • Android多套環(huán)境的維護(hù)思路詳解

    Android多套環(huán)境的維護(hù)思路詳解

    這篇文章主要為大家介紹了Android多套環(huán)境的維護(hù)思路詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2022-11-11
  • 基于SQLite的Android登錄APP

    基于SQLite的Android登錄APP

    這篇文章主要為大家詳細(xì)介紹了基于SQLite的Android登錄APP,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2021-01-01
  • Android自定義滾動(dòng)選擇器實(shí)例代碼

    Android自定義滾動(dòng)選擇器實(shí)例代碼

    本篇文章主要介紹了Android自定義滾動(dòng)選擇器實(shí)例代碼,具有一定的參考價(jià)值,有興趣的可以了解一下。
    2017-01-01
  • Android多功能視頻播放器GSYVideoPlayer開(kāi)發(fā)流程

    Android多功能視頻播放器GSYVideoPlayer開(kāi)發(fā)流程

    怎么在Android中實(shí)現(xiàn)GSYVideoPlayer視頻播放器?很多新手對(duì)此不是很清楚,為了幫助大家解決這個(gè)難題,下面小編將為大家詳細(xì)講解,有這方面需求的人可以來(lái)學(xué)習(xí)下,希望你能有所收獲
    2022-11-11
  • android實(shí)現(xiàn)上滑屏幕隱藏底部菜單欄的示例

    android實(shí)現(xiàn)上滑屏幕隱藏底部菜單欄的示例

    這篇文章主要介紹了android實(shí)現(xiàn)上滑屏幕隱藏底部菜單欄的示例,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2018-02-02
  • Android 多線程處理之多線程詳解

    Android 多線程處理之多線程詳解

    本文主要介紹Android 多線程處理的知識(shí)資料,這里整理下來(lái)詳細(xì)的知識(shí),和簡(jiǎn)單代碼實(shí)現(xiàn)和實(shí)現(xiàn)效果圖,有需要的朋友可以參考下
    2016-09-09
  • android中Handle類的用法實(shí)例分析

    android中Handle類的用法實(shí)例分析

    這篇文章主要介紹了android中Handle類的用法,以實(shí)例形式較為詳細(xì)的分析了基于Handle類線程執(zhí)行的相關(guān)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下
    2015-09-09
  • Android獲取其他應(yīng)用中的assets資源

    Android獲取其他應(yīng)用中的assets資源

    今天小編就為大家分享一篇關(guān)于Android獲取其他應(yīng)用中的assets資源,小編覺(jué)得內(nèi)容挺不錯(cuò)的,現(xiàn)在分享給大家,具有很好的參考價(jià)值,需要的朋友一起跟隨小編來(lái)看看吧
    2019-01-01
  • Android WebView使用方法詳解 附j(luò)s交互調(diào)用方法

    Android WebView使用方法詳解 附j(luò)s交互調(diào)用方法

    這篇文章主要為大家詳細(xì)介紹了Android WebView使用方法詳解,文中附j(luò)s交互調(diào)用方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2016-05-05
  • Android Studio實(shí)現(xiàn)音樂(lè)播放器

    Android Studio實(shí)現(xiàn)音樂(lè)播放器

    這篇文章主要為大家詳細(xì)介紹了Android Studio實(shí)現(xiàn)音樂(lè)播放器,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2020-11-11

最新評(píng)論