java - 使用 ViewPropertyAnimation 将对象从不可见缩放到可见
问题描述
有没有办法使用 ViewPropertyAnimation 使我的对象从不可见变为可见?我想把它移到一个位置。当我的对象移动到这个位置时,我想将它的大小增加到原来的大小。
btn.Animate()
.TranslationX(0)
.TranslationY(-250)
.SetDuration(1000)
.SetInterpolator(new OvershootInterpolator(4))
.ScaleXBy(0).ScaleX(1);
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>
解决方案
您可以先设置 ScaleX(0),然后使用 ScaleX(1) 将其设置为通过某些触发器将大小增加到原来的大小,例如单击按钮。所以代码是这样的:
[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);
}
}
推荐阅读
- python - 如何更改 PSD 图中的 yticks?
- javascript - 如何在 chrome 扩展中获取默认浏览器
- lsf - 如何在 lsf 中设置最大运行作业数
- java - 每类单例,防止额外的实例
- docker - 来自守护进程的错误响应:mob-someserver-L-1:5000/appdynamicsagent:B40 的清单未找到:清单未知:清单未知
- sql - PL/SQL 查询中的 NULL 处理增强
- ssas - SSAS 表格 DMV 获取表的源查询
- c# - 使用 App.Config 派生要使用的类/变量
- javascript - JavaScript:关于从字符串到整数的转换方式的性能
- python-3.x - 我正在尝试使用 'IF' 和 'OR' 函数在新列中具有值