0

So I have a basic "expandable" textview. Basically, what it does is, on the click of the title, it makes a TextView visible and animates it coming in from the top.

My problem is: when I click the title, the "empty space" for the TextView is added and the "content below" is pushed down right away. Is there any way I can make the "content below" slide down as the TextView slides down?

enter image description here

Main Activity

public class MainActivity extends ActionBarActivity {

TextView txt_help_gest;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    txt_help_gest = (TextView) findViewById(R.id.txt_help_gest);
    // hide until its title is clicked
    txt_help_gest.setVisibility(View.GONE);
}

/**
 * onClick handler
 */
public void toggle_contents(View v) {

    if (txt_help_gest.isShown()) {
        txt_help_gest.setVisibility(View.GONE);
    } else {
        txt_help_gest.setVisibility(View.VISIBLE);
        Fx.slide_down(this, txt_help_gest);
    }
}
}

FX Class

public class Fx {

public static void slide_down(Context ctx, View v){

      Animation a = AnimationUtils.loadAnimation(ctx, R.anim.slide_down);
      if(a != null){
         a.reset();
         if(v != null){
          v.clearAnimation();
          v.startAnimation(a);
         }
      }
}

}

XML

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:gravity="center_horizontal"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.expandablepanel.MainActivity" >

<TextView
    android:id="@+id/help_title_gest"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:clickable="true"
    android:textSize="30sp"
    android:onClick="toggle_contents"
    android:text="My Clickable Title" />

<!-- content to hide/show -->

<TextView
    android:id="@+id/txt_help_gest"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="All of this \nis my content \nthat will open \nwhen I click \non the title" />

<TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textSize="20sp"
    android:text="This is my content below" />

</LinearLayout>

Animation

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:fillAfter="true" >

<scale
    android:duration="1000"
    android:fromXScale="1.0"
    android:fromYScale="0.0"
    android:interpolator="@android:anim/linear_interpolator"
    android:toXScale="1.0"
    android:toYScale="1.0" />

</set>
user1282637
  • 1,827
  • 5
  • 27
  • 56
  • @XaverKapeller I'm not looking to reverse it...did you read the question right? I want to make the content below it push down as the animation slides down, so it looks like the text coming down is "pushing" the textview downward – user1282637 Sep 08 '14 at 16:20
  • @XaverKapeller doesn't seem to be working – user1282637 Sep 08 '14 at 16:30
  • I would be willing to use a different technique if you had one in mind, obviously it won't be too difficult since I am only using a simple animation – user1282637 Sep 08 '14 at 16:32
  • setFillEnabled() also didn't work. I guess I'll try another approach – user1282637 Sep 08 '14 at 16:41

0 Answers0