English 中文(简体)
Android 动画 - 初始视图状态
原标题:Android animation - Initial state of view

我得到了一个 < code> 动画 ,它导致从屏幕向右滑出一个视图,这与预期的以下代码相同:

Animation outtoRight = new TranslateAnimation(
         Animation.RELATIVE_TO_SELF,  0.0f, Animation.RELATIVE_TO_SELF,  +1.0f,
         Animation.RELATIVE_TO_SELF,  0.0f, Animation.RELATIVE_TO_SELF,   0.0f
        );
outtoRight.setDuration(500);
outtoRight.setInterpolator(new AccelerateInterpolator());
outtoRight.setFillAfter(true);

这意味着我应用此动画的视图将会美丽地从屏幕上滑出。 当然,我有一个相反的滑动。 但我的问题是, 我如何能将它从屏幕上移出, 这样我就可以在不将动画至少应用一次的情况下滑入屏幕中?

我玩过负负差之类的游戏, 但我似乎找不到合适的属性 使我的观点在发射时离开屏幕。

仅仅为了澄清,我可以从另一个动画开始完全隐藏它,但我能看到它消失,哪怕只是一秒钟。 一定有办法让它在一开始不在那里,然后让我在之后滑动。

最佳回答

我不是动画专家,

这是我正在使用的动画, 它从右侧滑入视图

< 强度 > EnterByyRight.xml

 <set xmlns:android="http://schemas.android.com/apk/res/android"
     android:shareInterpolator="false">
    <translate android:fromXDelta="100%" android:toXDelta="0%"
      android:fromYDelta="0%" android:toYDelta="0%"
     android:duration="400"/>
   </set>

在我的案例中,我正在动画一个在 xml 中定义的表格Layout。 当我想要它滑入时 :

Animation animationEnterByRight = AnimationUtils.loadAnimation(this, R.anim.animationentrancebyright);
tableLayout.startAnimation(animationEnterByRight);

它来自屏幕外, 我不需要先把它放在外面, 动画会照顾我。 如果您想在视图装满后立即动画的话, 这很好 。

如果您需要保留您的观点“ 隐形” 一段时间, 然后显示动画, 除了 View. 可视与 View. Gone 之外, 我无法思考任何其他解决方案 。 但我不明白为什么会有问题?

干杯! 干杯! 干杯! 干杯!

问题回答

一个可能的解决办法(因为这个问题的受人欢迎程度很低)可能是我目前使用的办法,尽管我根本不喜欢。我的观点是让 View.GONE 具有可见性,并应用动画让它向右移。

然后,第一次(我控制它,这是第一次在视图上贴标签) 我将可见度设定为 View.VISIBEL , 并应用动画来滑入。 这和预期的一样,没有破碎和跳跃, 但我仍然担心在很多元素中添加动画会同时与性能相关。

事实上,您自己的答案并不坏。 我唯一要改变的是, 您不能设置 Gone 来查看可行性, 而是用 addChild () 手工创建和添加它 。

以分开的线条执行, 以分开的线条添加动画, 并在主线上只拨addChild ()

一般来说, 您应该对分开的线条做内线处理, 这样UI 线条就不会生效, 如果需要0. 4 秒时间, 您应该开始播放一个至少0. 5 秒的装入动画 。 这是最好的 UI 练习, 我可以告诉你, 我在我的应用程序里做了, 并且效果很好!

您可以尝试 outto right.set FillBeore( false); 吗?

您可以使用 PreDrawListner () 来设置屏幕绘制前的视图位置, 然后为其运行幻灯片动画 。

yourview.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
    @Override
        public boolean onPreDraw() {
            yourview.getViewTreeObserver().removeOnPreDrawListener(this);
            yourview.setTranslationX(something that will take it out of the screen, depends on padding);
            yourview.runIntroAnimation();
            return false;
       }
};




相关问题
Android - ListView fling gesture triggers context menu

I m relatively new to Android development. I m developing an app with a ListView. I ve followed the info in #1338475 and have my app recognizing the fling gesture, but after the gesture is complete, ...

AsyncTask and error handling on Android

I m converting my code from using Handler to AsyncTask. The latter is great at what it does - asynchronous updates and handling of results in the main UI thread. What s unclear to me is how to handle ...

Android intent filter for a particular file extension?

I want to be able to download a file with a particular extension from the net, and have it passed to my application to deal with it, but I haven t been able to figure out the intent filter. The ...

Android & Web: What is the equivalent style for the web?

I am quite impressed by the workflow I follow when developing Android applications: Define a layout in an xml file and then write all the code in a code-behind style. Is there an equivalent style for ...

TiledLayer equivalent in Android [duplicate]

To draw landscapes, backgrounds with patterns etc, we used TiledLayer in J2ME. Is there an android counterpart for that. Does android provide an option to set such tiled patterns in the layout XML?

Using Repo with Msysgit

When following the Android Open Source Project instructions on installing repo for use with Git, after running the repo init command, I run into this error: /c/Users/Andrew Rabon/bin/repo: line ...

Android "single top" launch mode and onNewIntent method

I read in the Android documentation that by setting my Activity s launchMode property to singleTop OR by adding the FLAG_ACTIVITY_SINGLE_TOP flag to my Intent, that calling startActivity(intent) would ...

From Web Development to Android Development

I have pretty good skills in PHP , Mysql and Javascript for a junior developer. If I wanted to try my hand as Android Development do you think I might find it tough ? Also what new languages would I ...

热门标签