Animate(ScaleAnimation)LinearLayout,当它的高度因添加/删除其中的视图而发生变化时

时间:2013-09-24 16:20:43

标签: android android-layout animation layout scaleanimation

我有一个LinearLayout&我里面有2个TextView。动态地我想隐藏一个TextView,或者我可以在运行时添加TextViews。我的问题是当TextView从LinearLayout中消失时,它立即崩溃。我希望在从LinearLayout中删除视图时为LinearLayout(ScaleAnimation)设置动画。

activity_main.xml中

<RelativeLayout 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:paddingBottom="@dimen/activity_vertical_margin"
      android:paddingLeft="@dimen/activity_horizontal_margin"
      android:paddingRight="@dimen/activity_horizontal_margin"
      android:paddingTop="@dimen/activity_vertical_margin"
      tools:context=".MainActivity" >

  <LinearLayout
    android:id="@+id/linearLayout1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_margin="10dp"
    android:background="#000"
    android:orientation="vertical" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="1dp"
        android:background="#fff"
        android:orientation="vertical"
        android:padding="10dp" >

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="10dp"
            android:text="Hello, World" />

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="10dp"
            android:text="Hello, World 2" />
    </LinearLayout>  
  </LinearLayout>

  <Button
       android:layout_width="match_parent"
       android:layout_height="wrap_content"
       android:layout_alignParentBottom="true"
       android:text="Remove TextView" />

</RelativeLayout>

布局快照...... enter image description here

我希望在第二个TextView从LinearLayout&amp;中删除时为LinearLayout设置动画。如果另一个TextView被添加到LinearLayout中。 ScaleAnimation适用于上述任务,但我不知道此类动画所需的值。

1 个答案:

答案 0 :(得分:0)

很确定你不再需要它了,但是对于未来的搜索者来说:

对于移除动画,可以使用view.setVisibility(View.INVISIBLE)使项目不可见,并在动画(addAnimationListener)之后有效地将其从线性布局中移除。当视图不可见时,其父级会持续测量它。

相关问题