国产片侵犯亲女视频播放_亚洲精品二区_在线免费国产视频_欧美精品一区二区三区在线_少妇久久久_在线观看av不卡

服務器之家:專注于服務器技術及軟件下載分享
分類導航

PHP教程|ASP.NET教程|Java教程|ASP教程|編程技術|正則表達式|C/C++|IOS|C#|Swift|Android|VB|R語言|JavaScript|易語言|vb.net|

服務器之家 - 編程語言 - Android - android實現攜程購票起始點位置交換

android實現攜程購票起始點位置交換

2022-03-06 20:44Mars-xq Android

這篇文章主要為大家詳細介紹了android實現攜程購票起始點位置交換,具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文實例為大家分享了android實現購票起始點位置交換的具體代碼,供大家參考,具體內容如下

效果圖:

android實現攜程購票起始點位置交換

點擊交換位置按鈕,北京和深圳布局交換位置。

xml布局文件:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
<?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代碼:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
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);//獲取坐標
    int[] endXLocation = new int[2];
    rightCityTextView.getLocationOnScreen(endXLocation);
    startX = startXLocation[0];//0為x坐標
    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) {
      }
    });
  }
}

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持服務器之家。

原文鏈接:https://blog.csdn.net/sinat_31057219/article/details/80604223

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 久久久久久高清 | 婷婷五月色综合 | 免费精品 | 久久女人精品 | 日美毛片| av中文字幕在线播放 | 欧美亚洲天堂 | 日韩成人在线影院 | a级毛片免费高清视频 | 亚洲视频二区 | 日韩在线小视频 | 99热国| 成人亚洲精品777777大片 | 成人欧美一区二区三区在线播放 | 欧美一区二区在线观看 | 一区二区日韩 | 欧美日韩一区二区三区不卡视频 | 羞羞视频免费看 | 一区二区三区在线看 | 国产一区二区三区四 | 黄色一级片免费播放 | 一级欧美一级日韩 | 国产成人精品av | 亚洲欧美中文日韩在线v日本 | 国产在线视频a | 7799精品视频天天看 | 成人精品动漫一区二区三区 | 福利视频网址导航 | 九九亚洲| av毛片| 日韩有码在线播放 | 色婷婷久久一区二区三区麻豆 | 国产色网| 亚洲国产aⅴ成人精品无吗 久久综合久久久 | 处女一级片 | 黄色国产大片 | 伊人春色在线播放 | 久久综合久久久 | 国产中文字幕在线免费观看 | 在线观看亚洲一区二区三区 | 亚洲一区二区中文字幕 |