我的视图完全位于屏幕之外,我试图将其设置为屏幕上的动画.
我打电话的时候:
view.startAnimation(tA);
Run Code Online (Sandbox Code Playgroud)
没有任何反应,tA.initialize和tA.applyTransformation永远不会被调用.
如果我在开始动画之前移动视图以使其中任何部分可见,则动画可以正常工作.
当视图位于父视图之外时,什么阻止视图被动画?
介绍:
我有一个LinearLayout,它包含两个子LinearLayout,如下所示:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/dual_pane"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal"
android:weightSum="1.0">
<!-- Screen 1 -->
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:background="#ff0000"
android:layout_weight="1">
</LinearLayout>
<!-- Screen 2 -->
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:background="#ff6600"
android:layout_weight="1">
</LinearLayout>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
最初,我希望"屏幕1"可以使用所有屏幕宽度.因此,我的R.id.dual_pane的weightSum属性为1.0.这很好用!如果weightSum = 1.0,屏幕1占据整个屏幕!
加载一些资源后,我将R.id.dual_pane weighSum更改为2.0,这会导致屏幕1和屏幕2的屏幕宽度减少50%.这也很完美.当weightSum = 2.0时,两个屏幕占据宽度的50%.
问题:
我想为weightSum属性设置动画,所以我的Screen2将会滑入.我的目标是HoneyComb,所以minSDK版本是11,我想,使用新的ObjectAnimator框架,我可以很容易地动画这个属性,以获得一个很好的平滑效果.我验证了LinearLayout确实有getWeightSum()和setWeightSum()方法(我认为这是使用ObjectAnimator所必需的).
自己的努力:
这是我使用ObjectAnimator显示和隐藏Screen2的代码:
private void showScreen2()
{
//Not-animated will work...
//mDualPane.setWeightSum(2.0f);
// Now try to animate the weightSum
float ws = mDualPane.getWeightSum();
ObjectAnimator anim = ObjectAnimator.ofFloat(mDualPane, "weightSum", ws, 2.0f);
anim.setDuration(5000);
anim.start();
}
private void hideScreen2()
{
//Not-animated will work...
//mDualPane.setWeightSum(1.0f);
// Now …Run Code Online (Sandbox Code Playgroud) 所以我有一个看起来像这样的视图:

我想要实现的是当用户在GridView上向下滚动时,整个视图向上移动以隐藏顶部的大图像.基本上,如果他们想要查看更多的gridview,则布局会向上滚动以增加gridview的大小.
但是当我真正这样做时,会发生以下情况:

它工作正常,除了GridView不会增加大小以填充屏幕中的新空间,因此窗口的下半部分全部为白色,如您所见.
以下是我到目前为止所做的事情:
private void hideHeader(boolean animate) {
if(animate) {
AnimatorSet set = new AnimatorSet();
set.playTogether(
ObjectAnimator.ofFloat(mImageHeader, "translationY", -mImageHeader.getHeight()),
ObjectAnimator.ofFloat(mShareButton, "translationY", -mImageHeader.getHeight()),
ObjectAnimator.ofFloat(mIndicator, "translationY", -mImageHeader.getHeight()),
ObjectAnimator.ofFloat(mViewPager, "translationY", -mImageHeader.getHeight())
);
set.setDuration(700l);
set.start();
}
else {
//TODO finish
}
}
Run Code Online (Sandbox Code Playgroud)
您可以从代码中看出,我正在使用ViewPager.在这种情况下,GridView实际上是一个片段,这是我第一次认为我的问题来自的地方.但是,不是ViewPager正在填充屏幕并且其内部的片段不是这样的情况,而是ViewPager本身不是垂直填充的:

这是父片段的XML(包含大图像,Share按钮和viewpager +指示符):
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:background="@android:color/white"
android:layout_width="match_parent"
android:layout_height="match_parent">
<include android:id="@+id/fp_abf"
layout="@layout/action_bar_footer"/>
<include android:id="@+id/fp_image_header"
layout="@layout/widget_image_header"
android:layout_below="@id/fp_abf"/>
<TextView android:id="@+id/fp_share_button"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_below="@id/fp_image_header"
android:gravity="center"
android:background="@drawable/selectable_action_button_grey_to_bit_green"
android:textSize="14dp"
android:textColor="@android:color/white"
android:text="@string/share_caps"/>
<com.viewpagerindicator.TabPageIndicator android:id="@+id/fp_indicator"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/fp_share_button"
android:background="@color/header_background"/>
<android.support.v4.view.ViewPager android:id="@+id/fp_pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/fp_indicator"/>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
我最初将它作为LinearLayout,但试图将其切换为相对,看看是否会产生任何差异(它没有).
正如您所看到的,ViewPager的layout_height为"match_parent",我认为它足以填充它可用的所有空间.我认为正在发生的事情是视图没有被告知它有更多的空间可以使用并因此重新绘制它的界限,但我不确定如何触发它自己. …