2

我正在尝试同时滑动两个 TextView。这些 TextViews 在一个 RelativeLayout 中,一个在另一个旁边。第一个动画很干净。但是当我再次单击时,在两个文本视图之间运行动画时会形成间隙。

在此处输入图像描述

这是我在布局中的 xml 文件(activity_main.xml)

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

    <TextView
        android:id="@+id/TextView01"
        android:layout_width="match_parent"
        android:layout_height="50dp"  
        android:background="#f00"
        android:gravity="center" />


    <TextView
        android:id="@+id/TextView02"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#000" />

</RelativeLayout>

MainActivity.java :

public class MainActivity extends Activity implements AnimationListener {

TextView txtView1;
TextView txtView2;  
double counter = 0;

@Override
protected void onCreate(Bundle savedInstanceState) {
    :
    :
    txtView1 = (TextView) findViewById(R.id.TextView01);
    txtView2 = (TextView) findViewById(R.id.TextView02);

    // load the animation
    :
    :       

    txtView1.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (counter == 0) {

                txtView2.setVisibility(View.VISIBLE);

                txtView2.startAnimation(blackLeft);
                txtView1.startAnimation(redLeft);
                counter++;

            } else {

                txtView2.setVisibility(View.VISIBLE);

                txtView2.startAnimation(blackRight);
                txtView1.startAnimation(redRight);

                counter--;
            }

        }
    });

}
    // Animation Listened Implementations
    :
    :
}

redLeft.xml:

<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:interpolator="@android:anim/linear_interpolator"
    android:shareInterpolator="false"
    android:fillAfter="true">
  <translate 
    android:fromXDelta="0%p"
    android:toXDelta="-15%p"  
    android:duration="300"
  />
</set>

blackLeft.xml:

<translate 
  android:fromXDelta="100%p"
  android:toXDelta="85%p"  
  android:duration="300"
/>

redRight.xml:

<translate
   android:fromXDelta="-15%p"
   android:toXDelta="0%p"
   android:duration="300" />

blackRight.xml:

<translate 
  android:fromXDelta="85%p"
  android:toXDelta="100%p"  
  android:duration="300"
  android:repeatCount="0"
/>
4

0 回答 0