当前位置:网站首页>The use of the attribute of the use of the animation and ButterKnife
The use of the attribute of the use of the animation and ButterKnife
2022-08-04 06:04:00 【N_Y_S】
重点
1.属性动画 2.黄油刀ButterKnife
内容
什么是属性动画:Property animation is from3.0and later(如果要兼容低版本,You can use a private version of the third-party onejar NineOldAndroid.jar,The usage is similar to the usage of the system).
Constantly control the property changes of the control to achieve the effect of animation,Generally we are some combination of attribute animation to achieve complex effects.
Usage of property animation
1.在xml文件中添加控件
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:orientation="vertical"
android:padding="15dp"
android:id="@+id/lv_root"
tools:context=".MainActivity">
<Button
android:id="@+id/btn_1"
android:layout_marginTop="15dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="动画一" />
<Button
android:id="@+id/btn_2"
android:layout_marginTop="15dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="动画二" />
<Button
android:id="@+id/btn_3"
android:layout_marginTop="15dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="动画三" />
<Button
android:id="@+id/btn_4"
android:layout_marginTop="15dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="animation four" />
<Button
android:id="@+id/btn_5"
android:layout_marginTop="15dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Animation five" />
<ImageView
android:id="@+id/img"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="15dp"
android:background="@mipmap/a006" />
</LinearLayout>2.在ActivityJavaThe click event of the button is set in the file
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
private Button btn_1;
private Button btn_2;
private Button btn_3;
private Button btn_4;
private Button btn_5;
private ImageView img;
private LinearLayout lv_root;
int width,height;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btn_1=findViewById(R.id.btn_1);
btn_2=findViewById(R.id.btn_2);
btn_3=findViewById(R.id.btn_3);
btn_4=findViewById(R.id.btn_4);
btn_5=findViewById(R.id.btn_5);
img=findViewById(R.id.img);
lv_root=findViewById(R.id.lv_root);
btn_1.setOnClickListener(this);
btn_2.setOnClickListener(this);
btn_3.setOnClickListener(this);
btn_4.setOnClickListener(this);
btn_5.setOnClickListener(this);
}
@Override
public void onClick(View view) {
switch (view.getId()){
case R.id.btn_1:
break;
case R.id.btn_2:
case R.id.btn_3:
break;
case R.id.btn_4:
break;
case R.id.btn_5:
break;
}
}
}3.Set the moving animation of the picture,(Here is the movement from top to bottom)
switch (view.getId()){
case R.id.btn_1:
width = lv_root.getWidth();
height = lv_root.getHeight();
ValueAnimator valueAnimator = ValueAnimator.ofInt(0, height / 4, height / 2, height / 4 * 3, height);
valueAnimator.setDuration(3000L);
valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator valueAnimator) {
int y= (Integer) valueAnimator.getAnimatedValue();
int x=width/2;
moveView(img,x,y);
}
});
valueAnimator.setInterpolator(new LinearInterpolator());
valueAnimator.start();
break;4.Set the rotation and zoom animation of the image
case R.id.btn_3:
AnimatorSet scaleSet=new AnimatorSet();
ValueAnimator setAnim=ValueAnimator.ofFloat(1.0f,0.5f,1.2f,1.0f,0.6f,1.2f,1.0f);
setAnim.setDuration(2000l);
ValueAnimator ra=ValueAnimator.ofInt(0,360);
ra.setDuration(2000l);
setAnim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator valueAnimator) {
float scale= (float)valueAnimator.getAnimatedValue();
img.setScaleX(scale);
img.setScaleY(scale);
}
});
ra.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator valueAnimator) {
int rotate=(int)valueAnimator.getAnimatedValue();
img.setRotation(rotate);
}
});
scaleSet.playTogether(setAnim,ra);
//scaleSet.play(setAnim).after(ra);
scaleSet.start();5.Animate the rotation gradient of the image
case R.id.btn_4:
ValueAnimator raValue=ValueAnimator.ofInt(0,360);
raValue.setDuration(1000l);
raValue.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator valueAnimator) {
int rotate= (int) valueAnimator.getAnimatedValue();
img.setRotation(rotate);
float alpha=valueAnimator.getAnimatedFraction();
img.setAlpha(alpha);
}
});
raValue.setInterpolator(new DecelerateInterpolator());
raValue.start();
break;ButterKnife的使用
1.引入依赖
implementation 'com.jakewharton:butterknife:10.2.3'// 添加此依赖 annotationProcessor 'com.jakewharton:butterknife-compiler:10.2.3'// 添加此规则
2.在java文件中使用,绑定控件
@BindView(R.id.button1)
Button button1;
@BindView(R.id.button2)
Button button2;
@BindView(R.id.button3)
Button button3;
@BindView(R.id.button4)
Button button4;3.在orCreateStart binding in
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
ButterKnife.bind(this);
}4.设置点击事件
@OnClick({R.id.button1,R.id.button2,R.id.button3,R.id.button4})
public void onClick(View v){
switch (v.getId()){
case R.id.button1:
Toast.makeText(this, "按钮1", Toast.LENGTH_SHORT).show();
break;
case R.id.button2:
Toast.makeText(this, "按钮2", Toast.LENGTH_SHORT).show();
break;
case R.id.button3:
Toast.makeText(this, "按钮3", Toast.LENGTH_SHORT).show();
break;
case R.id.button4:
Toast.makeText(this, "按钮4", Toast.LENGTH_SHORT).show();
break;
}
}边栏推荐
- Logistic Regression --- Introduction, API Introduction, Case: Cancer Classification Prediction, Classification Evaluation, and ROC Curve and AUC Metrics
- (十)树的基础部分(二)
- 字典特征提取,文本特征提取。
- CTFshow—Web入门—信息(1-8)
- flink-sql所有表连接器
- 【CV-Learning】卷积神经网络
- VScode配置PHP环境
- EPSON RC+ 7.0 使用记录一
- (六)递归
- 【树 图 科 技 头 条】2022年6月28日 星期二 伊能静做客树图社区
猜你喜欢
随机推荐
(TensorFlow)——tf.variable_scope和tf.name_scope详解
安卓连接mysql数据库,使用okhttp
关系型数据库-MySQL:约束管理、索引管理、键管理语句
关系型数据库-MySQL:错误日志(log_error)
Vulnhub:Sar-1
SQL练习 2022/6/30
The pipeline mechanism in sklearn
智能合约安全——私有数据访问
Logistic Regression --- Introduction, API Introduction, Case: Cancer Classification Prediction, Classification Evaluation, and ROC Curve and AUC Metrics
PHP课堂笔记(一)
Kubernetes集群安装
剑指 Offer 2022/7/9
TensorFlow2学习笔记:8、tf.keras实现线性回归,Income数据集:受教育年限与收入数据集
flink on yarn指定第三方jar包
Matplotlib中的fill_between;np.argsort()函数
k3s-轻量级Kubernetes
自动化运维工具Ansible(7)roles
TensorFlow:tf.ConfigProto()与Session
(十六)图的基本操作---两种遍历
flink-sql自定义函数









