Android 设置ListView的动画,而不将动画应用于标题

Android 设置ListView的动画,而不将动画应用于标题,android,animation,android-listview,Android,Animation,Android Listview,我目前有一个附加了页眉和页脚的listview。我现在尝试在列表本身中设置项目的动画,但是当我将layoutaimationcontroller应用于列表视图时,标题也会设置动画。有没有一种方法可以在不影响标题的情况下将动画应用于整个列表 目前,我已经尝试了通过创建一个LinearLayout子类来检查是否可设置动画的解决方案,但是标题仍然与其他项目一起设置动画 public class AnimationAverseLinearLayout extends LinearLayout {

我目前有一个附加了页眉和页脚的listview。我现在尝试在列表本身中设置项目的动画,但是当我将
layoutaimationcontroller
应用于列表视图时,标题也会设置动画。有没有一种方法可以在不影响标题的情况下将动画应用于整个列表

目前,我已经尝试了通过创建一个LinearLayout子类来检查是否可设置动画的解决方案,但是标题仍然与其他项目一起设置动画

public class AnimationAverseLinearLayout extends LinearLayout {
    private boolean mIsAnimatable = true;

    public AnimationAverseLinearLayout(Context context) {
        super(context);
    }

    public AnimationAverseLinearLayout(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public void setAnimatable(boolean isAnimatable) {
        if(!isAnimatable)
            clearAnimation();
        mIsAnimatable = isAnimatable;
    }     

    @Override
    public void startAnimation(Animation animation) {
        if(mIsAnimatable) {
            super.startAnimation(animation);
        }
    }
}


这并不是最好的解决方案,但它是否可以替代例如:

  • 创建容器视图(
    LinearLayout
    带垂直方向)
  • 添加标题视图
  • 添加您的
    列表视图
  • 添加页脚视图
我的意思是,页眉和页脚将独立于您的列表组件,并将是一个快速修复。不是吗?例如,您仍然能够控制页眉/页脚的可见性,只需将可见性设置为
View.GONE

还有1,您还有其他方法可以实现吗?我是说,
canAnimate
或类似的东西? 还有2,您的
getView
方法是如何实现的

仅提供一个我所解释的快速示例:

<!-- Scrollable container -->
<ScrollView
    android:id="@+id/scrollContainer"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <!-- Container view -->
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/list"
        android:orientation="vertical">

        <!-- Header view -->
        <TextView
            android:id="@+id/header"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="@string/header_text" />

        <!-- LinearLayout acting as ListView -->
        <LinearLayout
            android:orientation="vertical"
            android:id="@+id/list"
            android:layout_width="match_parent"
            android:layout_height="match_parent" >

            <!-- Insert rows into the fake list -->
            <TextView
                android:id="@+id/row_item"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="@string/row_item" />

        </LinearLayout>

        <!-- Footer view -->
        <TextView
            android:id="@+id/footer"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="@string/footer_text" />
    </LinearLayout>
</ScrollView>


我相信问题现在已经解决了:)

如果您想查看这个xml文件,我会这样做

我在此声明页眉和页脚分开&Listview分开,如果您想,您可以设置Listview的动画。页眉和页脚将无法设置动画

如果你给页眉和页脚设置动画,那么它也会设置动画

<?xml version="1.0" encoding="utf-8"?>
<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" >

  <!-- Header aligned to top -->
  <RelativeLayout
    android:id="@+id/header"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:background="#FC9"
    android:gravity="center" >

    <TextView
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_margin="5dp"
      android:text="Fixed Header"
      android:textColor="#000"
      android:textSize="20sp" />
  </RelativeLayout>

  <!-- Footer aligned to bottom -->
  <RelativeLayout
    android:id="@+id/footer"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:background="#FC0"
    android:gravity="center" >

    <TextView
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_margin="5dp"
      android:text="Fixed Footer"
      android:textColor="#000"
      android:textSize="20sp" />
  </RelativeLayout>

  <!-- LIstview Item below header and above footer -->

  <ListView
      android:id="@+id/listView1"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:layout_above="@+id/footer"
      android:layout_alignParentLeft="true"
      android:layout_below="@+id/header" >

  </ListView>

</RelativeLayout> 

我遇到了上述相同的问题-动画应用于ListView标题以及列表行。我在他的帮助下解决了这个问题。我对标题的最外层视图(在我的例子中是FrameLayout)进行了子类化,并重写了动画方法以不采取任何操作。例如:

list_header.xml:

<my.project.NonAnimatingFrameLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  ...
  >
 <!-- other views in your header -->
 ...
</my.project.NonAnimatingFrameLayout>

您需要覆盖my的动画方法根据最外层视图的类型而有所不同。

是否有类似的gif视频来查看您想要实现的动画类型?您在这方面有什么进展吗?我的回答有帮助吗?:)动画类型应该无关紧要,因为任何动画都会以相同的方式影响视图。不过,为了参数起见,我正在对视图进行alpha/translate设置。Matheus,我唯一的进展是我将动画移到了包装适配器的getView中,它可以工作,但并不理想,因为这样可以在滚动时为所有视图设置动画,这在一个包含300个结果的列表中可能太过突出。顺便说一句,我发现了这个非常酷的listview项目-检查:嗨,你解决了这个问题吗?我在寻找同样的东西:)像这样解决它的问题是,你正在使页眉和页脚固定,但我希望它们能够与listview一起滚动,这就是为什么我让它们作为页眉和页脚直接添加到listview中你是对的,明白了!但是外部线性布局不能成为滚动视图吗?或者用滚动视图包围一切?不,不行。如果外部布局是滚动视图,则listview将丢失其触摸事件,不再滚动。此外,我还需要ListView的onScollChangeListener,它在ScrollViewAssure中没有类似的方法,我将研究其他替代方法。您是否尝试过我提到的
canAnimate
方法?是的,我尝试在自定义布局中覆盖canAnimate方法,但layoutaimationcontroller仍会对其设置动画。您的解决方案与@matheusjarimb存在相同的问题。通过在带有listview的ViewGroup容器中绘制页眉和页脚,可以使它们成为静态的。但是,我希望页眉和页脚与列表项一起滚动。
<my.project.NonAnimatingFrameLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  ...
  >
 <!-- other views in your header -->
 ...
</my.project.NonAnimatingFrameLayout>
package my.project

public class NonAnimatingFrameLayout extends FrameLayout {
  ...
  @Override
  public void setAnimation(Animation animation) {
    // do nothing 
  }