国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > Android > 正文

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

2019-10-21 21:49:27
字體:
來源:轉載
供稿:網友

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

效果圖:

android,攜程,購票

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

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);//獲取坐標    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) {      }    });  }}

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持VEVB武林網。


注:相關教程知識閱讀請移步到Android開發頻道。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 莲花县| 湟源县| 宜君县| 内丘县| 楚雄市| 青龙| 寿光市| 濮阳市| 财经| 静安区| 古田县| 尼勒克县| 九江县| 鲁山县| 光泽县| 会泽县| 新民市| 容城县| 民县| 沧州市| 康保县| 新沂市| 平乐县| 大化| 合肥市| 鄂州市| 麻江县| 刚察县| 水城县| 公安县| 封丘县| 汾阳市| 涞水县| 来宾市| 通化县| 蒙自县| 东城区| 长乐市| 蕉岭县| 新绛县| 河间市|