2

I am trying to slide two TextViews at the same time. These TextViews are in one RelativeLayout and one beside the other. First animation is clean. But when I click again, there is a gap forming while animation runs between two textviews.

enter image description here

This is my xml file in layout(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"
/>
Kousik
  • 21,485
  • 7
  • 36
  • 59
  • 2
    see my answer to: http://stackoverflow.com/questions/19098083/how-to-animate-a-slide-in-notification-view-that-pushes-the-content-view-down/19098369#19098369 I think that might help you on the way. – cYrixmorten Oct 24 '13 at 16:06

0 Answers0