该方法的实现目的:以整形初始值平稳过渡到整形结束值。

比如 ValueAnimator.ofInt(0,100) , 实现的即数值从0平稳的变化到100

 

比如实现如下一个效果:

改变控件的样式,圆形和圆角长方形切换

实现思路很简单,即高度不变,改变控件的宽度(圆形时:宽高相等,长方形时:宽度为屏幕宽度-两边边距),顺便设置一个背景值,动画执行过程随便设个值(例子250毫秒)

属性动画的核心方法:ValueAnimator.ofInt(int... values)

 

现在看具体实现:

1、首先布局文件,设置两个按钮和一个效果控件 , 这里设置执行效果控件的高度固定为50dp,当然可以自行扩展

 1 <?xml version="1.0" encoding="utf-8"?>
 2 <LinearLayout xmlns:andro
 3     xmlns:app="http://schemas.android.com/apk/res-auto"
 4     xmlns:tools="http://schemas.android.com/tools"
 5     android:layout_width="match_parent"
 6     android:layout_height="match_parent"
 7     android:orientation="vertical"
 8     android:gravity="center"
 9     tools:context=".MainActivity">
10 
11     <TextView
12         android:
13         android:layout_width="wrap_content"
14         android:layout_height="wrap_content"
15         android:gravity="center"
16         android:text="长方形变圆形"
17         android:padding="10dp"
18         ></TextView>
19 
20 
21     <TextView
22         android:
23         android:layout_width="wrap_content"
24         android:layout_height="wrap_content"
25         android:gravity="center"
26         android:text="圆形变长方形"
27         android:padding="10dp"
28         android:layout_marginTop="20dp"
29         ></TextView>
30 
31 
32     <TextView
33         android:
34         android:layout_width="match_parent"
35         android:layout_height="50dp"
36         android:text="+"
37         android:gravity="center"
38         android:textColor="#fff"
39         android:background="@drawable/shape_main_add_rect"
40         app:layout_constraintRight_toRightOf="parent"
41         android:layout_marginRight="30dp"
42         android:layout_marginLeft="30dp"
43         android:layout_marginTop="30dp"
44         app:layout_constraintBottom_toBottomOf="parent"
45         android:layout_marginBottom="30dp"
46         />
47 
48 </LinearLayout>
xml布局文件

相关文章:

  • 2022-12-23
  • 2021-06-24
  • 2021-10-10
  • 2021-12-09
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-04-18
猜你喜欢
  • 2021-10-06
  • 2021-12-09
  • 2021-11-23
  • 2021-10-10
相关资源
相似解决方案