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

android實(shí)現(xiàn)攜程購(gòu)票起始點(diǎn)位置交換

 更新時(shí)間:2018年06月28日 09:42:38   作者:Mars-xq  
這篇文章主要為大家詳細(xì)介紹了android實(shí)現(xiàn)攜程購(gòu)票起始點(diǎn)位置交換,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了android實(shí)現(xiàn)購(gòu)票起始點(diǎn)位置交換的具體代碼,供大家參考,具體內(nèi)容如下

效果圖:

點(diǎn)擊交換位置按鈕,北京和深圳布局交換位置。

xml布局文件:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:fitsSystemWindows="true"
  android:orientation="horizontal">

  <TextView
    android:id="@+id/left_tv"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:gravity="center"
    android:text="北京" />

  <Button
    android:id="@+id/btn"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:gravity="center"
    android:text="交換位置" />

  <TextView
    android:id="@+id/right_tv"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:gravity="center"
    android:text="深圳" />

</LinearLayout>

java代碼:

public class TESTButtonActivity extends AppCompatActivity {
  private int startX;
  private int endX;
  private TextView leftCityTextView;
  private TextView rightCityTextView;
  private ValueAnimator endCityAnimator;
  private ValueAnimator startCityAnimation;

  @Override
  protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_button);

    leftCityTextView = ((TextView) this.findViewById(R.id.left_tv));
    rightCityTextView = ((TextView) this.findViewById(R.id.right_tv));

    Button mBtn = ((Button) this.findViewById(R.id.btn));
    mBtn.setOnClickListener(new View.OnClickListener() {
      @Override
      public void onClick(View v) {
        startCityAnimation.start();
        endCityAnimator.start();
      }
    });
  }

  private void getLocation() {
    int[] startXLocation = new int[2];
    leftCityTextView.getLocationOnScreen(startXLocation);//獲取坐標(biāo)
    int[] endXLocation = new int[2];
    rightCityTextView.getLocationOnScreen(endXLocation);
    startX = startXLocation[0];//0為x坐標(biāo)
    endX = endXLocation[0];
  }

  @Override
  public void onWindowFocusChanged(boolean hasFocus) {
    super.onWindowFocusChanged(hasFocus);

    getLocation();

    int leftMoveX = endX - startX;
    int rightMoveX = endX - startX;

    startCityAnimation = ValueAnimator.ofInt(0, leftMoveX).setDuration(5000);
    startCityAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
      @Override
      public void onAnimationUpdate(ValueAnimator animation) {
        int value = (int) animation.getAnimatedValue();
        //重新布局
        leftCityTextView.layout(startX + value,
            leftCityTextView.getTop(),
            startX + value + leftCityTextView.getWidth(),
            leftCityTextView.getBottom());
      }
    });

    endCityAnimator = ValueAnimator.ofInt(0, rightMoveX).setDuration(5000);
    endCityAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
      @Override
      public void onAnimationUpdate(ValueAnimator animation) {
        int value = (int) animation.getAnimatedValue();
        //重新布局
        rightCityTextView.layout(endX - value,
            rightCityTextView.getTop(),
            endX + rightCityTextView.getWidth() - value,
            rightCityTextView.getBottom());
      }
    });

    endCityAnimator.addListener(new Animator.AnimatorListener() {
      @Override
      public void onAnimationStart(Animator animation) {
      }

      @Override
      public void onAnimationEnd(Animator animation) {
        //用于下次交換
        TextView tempTextView = leftCityTextView;
        leftCityTextView = rightCityTextView;
        rightCityTextView = tempTextView;
      }

      @Override
      public void onAnimationCancel(Animator animation) {
      }

      @Override
      public void onAnimationRepeat(Animator animation) {
      }
    });
  }
}

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

相關(guān)文章

  • 淺析Kotlin使用infix函數(shù)構(gòu)建可讀語(yǔ)法流程講解

    淺析Kotlin使用infix函數(shù)構(gòu)建可讀語(yǔ)法流程講解

    這篇文章主要介紹了淺析Kotlin使用infix函數(shù)構(gòu)建可讀語(yǔ)法,我們?cè)贙otlin中就多次使用A to B這樣的語(yǔ)法結(jié)構(gòu)構(gòu)建鍵值對(duì),包括Kotlin自帶的mapOf()函數(shù),這種語(yǔ)法結(jié)構(gòu)的優(yōu)點(diǎn)是可讀性強(qiáng)
    2023-01-01
  • 詳解Android10的分區(qū)存儲(chǔ)機(jī)制(Scoped Storage)適配教程

    詳解Android10的分區(qū)存儲(chǔ)機(jī)制(Scoped Storage)適配教程

    這篇文章主要介紹了詳解Android10的分區(qū)存儲(chǔ)機(jī)制(Scoped Storage)適配教程,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2020-05-05
  • Android App支付系列(二):支付寶SDK接入詳細(xì)指南(附官方支付demo)

    Android App支付系列(二):支付寶SDK接入詳細(xì)指南(附官方支付demo)

    本篇文章介紹了Android App支付系列(二):支付寶SDK接入詳細(xì)指南(附官方支付demo) ,有興趣的同學(xué)可以了解一下。
    2016-11-11
  • 深入理解Android MD5數(shù)據(jù)加密

    深入理解Android MD5數(shù)據(jù)加密

    在Android中需要對(duì)各種數(shù)據(jù)進(jìn)行加密的操作,比如用戶短信備份的數(shù)據(jù)加密、用戶賬戶登陸的密碼加密以及應(yīng)用于服務(wù)器連接傳遞重要數(shù)據(jù)的加密,用處非常的多,所以今天來(lái)總結(jié)一下MD5加密算法。
    2016-09-09
  • Android Studio自動(dòng)排版的兩種實(shí)現(xiàn)方式

    Android Studio自動(dòng)排版的兩種實(shí)現(xiàn)方式

    這篇文章主要介紹了Android Studio自動(dòng)排版的兩種實(shí)現(xiàn)方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2020-03-03
  • Android彈出窗口實(shí)現(xiàn)方法

    Android彈出窗口實(shí)現(xiàn)方法

    這篇文章主要介紹了Android彈出窗口實(shí)現(xiàn)方法,涉及Android TextView及鼠標(biāo)事件的響應(yīng)相關(guān)技巧,需要的朋友可以參考下
    2016-01-01
  • android實(shí)現(xiàn)記事本app

    android實(shí)現(xiàn)記事本app

    這篇文章主要為大家詳細(xì)介紹了android實(shí)現(xiàn)記事本app的相關(guān)代碼 ,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-12-12
  • Android實(shí)現(xiàn)圓角矩形和圓形ImageView的方式

    Android實(shí)現(xiàn)圓角矩形和圓形ImageView的方式

    這篇文章主要為大家詳細(xì)介紹了Android中實(shí)現(xiàn)圓角矩形和圓形的方式,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2016-09-09
  • 如何在Android Studio下進(jìn)行NDK開發(fā)

    如何在Android Studio下進(jìn)行NDK開發(fā)

    這篇文章主要介紹了如何在Android Studio下進(jìn)行NDK開發(fā),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2020-05-05
  • Android基于TextView實(shí)現(xiàn)跑馬燈效果

    Android基于TextView實(shí)現(xiàn)跑馬燈效果

    這篇文章主要為大家詳細(xì)介紹了Android基于TextView實(shí)現(xiàn)跑馬燈效果的相關(guān)資料,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-03-03

最新評(píng)論