Android:使用动画显示/隐藏视图

新手上路,请多包涵

我一直在这里查看许多谷歌结果/问题,以确定如何通过垂直动画显示/隐藏视图,但我似乎找不到完全正确或不太模糊的视图。

我有一个位于另一个布局下方和多个其他小部件上方的布局(撤消栏);此撤消栏应垂直滑动打开和滑动关闭,具体取决于具体情况。

目前我现在所做的就是将视图设置为可见或消失。

原文由 Blaskovicz 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 428
1 个回答

视图动画师:

在 XML 中:

   <ViewAnimator
    android:id="@+id/animator_message"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:inAnimation="@anim/slide_down_text"
    android:outAnimation="@anim/slide_up_text">

    <TextView
        android:id="@+id/text_message_authentication"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center_horizontal"
        android:text="message_error_authentication" />

    <TextView
        android:id="@+id/text_message_authentication_connection"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center_horizontal"
        android:text="message_error_authentication_connection" />

    <TextView
        android:id="@+id/text_message_authentication_empty"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center_horizontal"
        android:text="message_error_authentication_field_empty" />

</ViewAnimator>

功能:

 public void show(int viewId) {
    ViewAnimator animator = (ViewAnimator) findView(animatorId);
    View view = findViewById(viewId);

    if (animator.getDisplayedChild() != animator.indexOfChild(view)) {
        animator.setDisplayedChild(animator.indexOfChild(view));
     }
 }

 private void showAuthenticationConnectionFailureMessage() {
    show(R.id.text_message_authentication_connection);
}

原文由 Ankush Shrivastava 发布,翻译遵循 CC BY-SA 4.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题