所以我有一个基本的"可扩展的" TextView中。基本上,它的作用是,在点击标题时,它使TextView可见,并使其从顶部进入动画。
我的问题是:当我点击标题时,"空白空间"添加TextView并在"内容下面"被推下来。我有什么方法可以制作下面的"内容"当TextView向下滑动时向下滑动?
主要活动
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类
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>
动画
<?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>