简体   繁体   English

使用ViewPropertyAnimation将对象从不可见缩放到可见

[英]Scale object from invisible to visible using ViewPropertyAnimation

Is there way to make my object look from invisible to visible using ViewPropertyAnimation? 是否可以使用ViewPropertyAnimation使我的对象从不可见变为可见? I want to move it in a position. 我想将其移动到一个位置。 While my object is moving to this position i want to increase it's size as original one. 当我的对象移动到这个位置时,我想增加它的大小,就像原来的一样。

btn.Animate()
.TranslationX(0)
.TranslationY(-250)
.SetDuration(1000)
.SetInterpolator(new OvershootInterpolator(4))
.ScaleXBy(0).ScaleX(1);

XML XML

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"  xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"><android.support.design.widget.FloatingActionButton

        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:id="@+id/button1" />

</RelativeLayout>

My Object is moved in right direction but it's size is remain the same. 我的对象向正确的方向移动,但其大小保持不变。 在此处输入图片说明

You can first set ScaleX(0), and then use ScaleX(1) to set it to increase the size to the original one by some trigger, for example, click a button. 您可以先设置ScaleX(0),然后使用ScaleX(1)对其进行设置,以通过某种触发将大小增加到原始大小,例如,单击一个按钮。 So the code is like this: 所以代码是这样的:

[Activity(Label = "Animation", Theme = "@style/AppTheme", MainLauncher = true)]
public class MainActivity : AppCompatActivity
{
    FloatingActionButton btn;
    Button btn2;
    protected override void OnCreate(Bundle savedInstanceState)
    {
        base.OnCreate(savedInstanceState);
        // Set our view from the "main" layout resource
        SetContentView(Resource.Layout.activity_main);
        btn = FindViewById<FloatingActionButton>(Resource.Id.button1);
        btn2 = FindViewById<Button>(Resource.Id.button2);
        btn2.Click += StartAnimate;
        btn.Animate().SetDuration(0).ScaleX(0);
    }

    private void StartAnimate(object sender, EventArgs e)
    {
        btn.Animate().SetStartDelay(100).TranslationX(0).TranslationY(-250).SetDuration(1000).SetInterpolator(new OvershootInterpolator(4)).ScaleX(1);
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM