2

我有一个 LinearLayout,里面有 2 个 TextView。动态地,我想隐藏一个 TextView,或者我可以在运行时添加 TextView。我的问题是当 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>

布局快照... 在此处输入图像描述

当从 LinearLayout 中删除第二个 TextView 并且将另一个 TextView 添加到 LinearLayout 时,我想为 LinearLayout 设置动画。ScaleAnimation 适用于上述任务,但我不知道此类动画所需的值。

4

1 回答 1

0

很确定您不再需要它,但对于未来的搜索者:

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

于 2014-02-23T16:51:21.753 回答