目前,我使用以下技术执行页脚 View 向上滑动动画。
// Start the animation.
ViewPropertyAnimator.animate(view).setStartDelay(2000).setDuration(2000).translationY(0).alpha(1.0f).setListener(new Animator.AnimatorListener() {
@Override
public void onAnimationStart(com.nineoldandroids.animation.Animator animation) {
ViewHelper.setTranslationY(view, view.getHeight());
ViewHelper.setAlpha(view, 0.0f);
view.setVisibility(View.VISIBLE);
}
@Override
public void onAnimationEnd(com.nineoldandroids.animation.Animator animation) {
view.setVisibility(View.VISIBLE);
}
@Override
public void onAnimationCancel(com.nineoldandroids.animation.Animator animation) {
}
@Override
public void onAnimationRepeat(com.nineoldandroids.animation.Animator animation) {
}
});
布局的 XML 如下
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<FrameLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<android.support.v7.widget.RecyclerView
android:id="@+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ff0000"
android:requiresFadingEdge="none"
android:scrollbars="vertical"
android:paddingTop="@dimen/default_tab_layout_height"
android:clipToPadding="false" />
<LinearLayout
android:paddingTop="@dimen/default_tab_layout_height"
android:id="@android:id/empty"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical">
<ProgressBar
android:id="@+id/progress_bar"
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<LinearLayout
android:id="@+id/not_found_linear_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical"
android:visibility="gone" >
<TextView android:textColor="?attr/dimForeground" android:textSize="44sp" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/sorry" />
<TextView android:textColor="?attr/dimForeground" android:textSize="16sp" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/no_buy_data_found" />
</LinearLayout>
</LinearLayout>
</FrameLayout>
<LinearLayout
android:id="@+id/touch_delegate_linear_layout"
android:orientation="vertical"
android:background="@android:color/transparent"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:id="@+id/footer_linear_layout"
android:layout_width="match_parent"
android:layout_height="48dp"
android:background="?attr/buyPortfolioFooterLinearLayoutBackground"
android:gravity="center_vertical"
android:orientation="horizontal" >
<TextView
android:id="@+id/footer_label_text_view"
android:text="@string/buy_portfolio_value"
android:layout_width="0dp"
android:width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"
android:layout_gravity="center_vertical"
android:paddingLeft="5dp"
android:textColor="?attr/buyPortfolioFooterTextViewColor"
android:textSize="18sp"
android:gravity="left|center_vertical"
android:background="?attr/buyPortfolioFooterTextViewSelector" />
<View
android:layout_width="1px"
android:layout_height="match_parent"
android:layout_marginTop="12dp"
android:layout_marginBottom="12dp"
android:background="?attr/buyPortfolioFooterDividerColor" />
<TextView
android:id="@+id/footer_value_text_view"
android:layout_width="0dp"
android:width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"
android:layout_gravity="center_vertical"
android:paddingRight="8dp"
android:textColor="?attr/buyPortfolioFooterTextViewColor"
android:textSize="18sp"
android:gravity="right|center_vertical" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#ff000000"
android:gravity="center_vertical"
android:orientation="horizontal" >
<TextSwitcher
android:id="@+id/status_bar"
android:width="0dp"
android:layout_width="0dp"
android:layout_weight="0.5"
android:layout_height="wrap_content"
android:paddingLeft="5dp"
android:layout_marginTop="2dp"
android:layout_marginBottom="2dp"
android:background="@android:color/transparent" />
<LinearLayout
android:id="@+id/currency_exchange_linear_layout"
android:background="?attr/buyPortfolioCurrencyExchangeLinearLayoutSelector"
android:gravity="right"
android:orientation="horizontal"
android:width="0dp"
android:layout_width="0dp"
android:layout_weight="0.5"
android:paddingRight="5dp"
android:paddingTop="2dp"
android:paddingBottom="2dp"
android:layout_height="wrap_content">
<TextSwitcher
android:id="@+id/currency_exchange_rate_text_switcher"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@android:color/transparent" />
<TextView
android:id="@+id/to_currency_text_view"
android:textColor="?attr/buyPortfolioStatusBarTextViewColor"
android:background="@android:color/transparent"
android:textSize="12sp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextSwitcher
android:id="@+id/currency_pair_text_switcher"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@android:color/transparent" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
动画正在 footer_linear_layout
上执行
这是动画的结果 - https://youtu.be/r1zQKpj2HVo
正如您所看到的,当底部页脚 View 向上滑动时,出现了一个不需要的白色矩形。
知道白色矩形从哪里来吗?我可以知道如何避免这种情况吗?
最佳答案
因为页脚下面没有任何东西。所以当它滑落时,你会得到一个空白区域。为了避免这种情况,您需要下面的数据,或者您需要对上面的内容进行增长然后收缩。如果你想这样做,我会认真研究 CoordinatorLayout 来减轻一些工作
关于android - 为什么当我们执行 View 向上滑动动画时会出现不需要的白色矩形,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36873821/