【发布时间】:2015-02-06 17:37:57
【问题描述】:
我有这样的布局
<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:animateLayoutChanges="true">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#fff"
android:id="@+id/relativeLayout">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/category_1_full"
android:scaleType="centerCrop"
android:id="@+id/categoryImageView" />
(...)
</RelativeLayout>
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/swipeRefreshLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentBottom="true"
android:layout_below="@+id/relativeLayout"
>
<GridView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/gridView"
android:numColumns="2"
android:verticalSpacing="10dp"
android:horizontalSpacing="10dp"
/>
</android.support.v4.widget.SwipeRefreshLayout>
</RelativeLayout>
然后我像这样为第一个相对布局设置动画
float _height = 120.05f;
ObjectAnimator a1 = ObjectAnimator.ofFloat(relativeLayout, "translationY", -_height);
ObjectAnimator a2 = ObjectAnimator.ofFloat(swipeRefreshLayout, "translationY", -_height);
a2.addUpdateListener(new ValueAnimator.AnimatorUpdateListener()
{
@Override
public void onAnimationUpdate(ValueAnimator animation)
{
swipeRefreshLayout.invalidate();
gridView.invalidate();
}
});
AnimatorSet animation = new AnimatorSet();
animation.play(a1).with(a2);
animation.start();
如您所见,我试图使相关视图无效到 updateListener 但它不起作用。
我认为由于布局上的关系(match_parent 和 alignXX),刷新/gridViews 会自动更新 但事实并非如此。我该怎么办?
【问题讨论】:
-
你能详细解释一下,你想做什么。无法理解您的问题。
-
我正在为
@+id/relativeLayout设置动画到顶部大约 120 像素,所以我希望 SwipeRefreshLayout 跟随该动画(因为 XML 上的规则指定了android:layout_below="@+id/relativeLayout")但事实并非如此。当然,我也可以在滑动布局上制作动画,但它不会保留android:layout_alignParentBottom="true"规则... -
另一种查看方式是:我如何为滑动高度(不是缩放)设置动画,使其保持在相对布局下和父底部
-
在动画中将
fillAfter="true"设置为您的@+id/relativeLayout。不要为滑动布局设置动画。 -
如您所见,我使用的是代码而不是 xml,所以我不确定该放在哪里?此外,该文档不清楚该功能,但据我了解,它似乎不相关。以防万一,我会朝着这个方向努力:)
标签: android