在第一次触摸时放大TextView,在第二次触摸时缩小

时间:2012-10-05 17:33:16

标签: android android-layout android-animation textview

我对Android比较陌生。

描述 -

我有一个LinearLayout,其中包含TextView个。 我正在动态添加TextView

当我触摸TextView时,我希望它ScaleUp,当我再次触摸TextView时,我希望它ScaleDown

我的问题是 -

  1. TextViewscaled up且任何其他TextViewtouched时。较旧的TextView scale downtouched TextView scale up应为scaled up
  2. 当我触摸TextView TextView时,此<set xmlns:android="http://schemas.android.com/apk/res/android"> <scale android:fromXScale="1.0" android:fromYScale="1.0" android:toXScale="3.0" android:toYScale="3.0" > </scale> 应缩小。
  3. 这就是我尝试过的

    我有2套xmls。 1用于放大

    <set xmlns:android="http://schemas.android.com/apk/res/android">
     <scale
        android:fromXScale="3.0"
        android:fromYScale="3.0"
        android:toXScale="1.0"
        android:toYScale="1.0" >
    </scale>
    

    和另一个缩小

    Activity

    我的myTextView.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_DOWN) { if (myTextView.getAnimation() == null) { Animation a = AnimationUtils.loadAnimation( getBaseContext(), R.anim.scale_up); a.setFillAfter(true); v.startAnimation(a); } else { v.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View v1, MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_DOWN) { Animation a1 = AnimationUtils .loadAnimation( getBaseContext(), R.anim.scale_down); a1.setFillAfter(true); v1.startAnimation(a1); } return true; } }); } } return false; } }); 课程 -

    {{1}}

1 个答案:

答案 0 :(得分:1)

在其中制作文本视图和存储状态的集合..在每次触摸时,您循环此集合并搜索正确的文本视图并使用它执行适当的操作。您还可以搜索此集合,并检查哪些文本视图按比例放大或缩小,因为您自己管理状态。

相关问题