Android 动画之属性动画,2021Android 开发面试解答之设计模式
1.透明动画:alpha
2.位移动画:translationX,translationY
3.旋转动画:rotation
4…缩放动画:scaleX,scaleY
5.组合显示:AnimatorSet(动画集合容器)
源码如下:
activity_third.xml 文件:
<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"
tools:context=".ThirdActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:id="@+id/btn_alpha"
android:layout_width="0dp"
android:layout_height="40dp"
android:layout_weight="1"
android:text="透明动画" />
<Button
android:id="@+id/btn_translate"
android:layout_width="0dp"
android:layout_height="40dp"
android:layout_weight="1"
android:text="位移动画" />
<Button
android:id="@+id/btn_rotate"
android:layout_width="0dp"
android:layout_height="40dp"
android:layout_weight="1"
android:text="旋转动画" />
<Button
android:id="@+id/btn_scale"
android:layout_width="0dp"
android:layout_height="40dp"
android:layout_weight="1"
android:text="缩放动画" />
</LinearLayout>
<ImageView
android:id="@+id/iv_show"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:src="@mipmap/ic_launcher" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:onClick="groupshow"
android:text="组合显示" />
</RelativeLayout>
ThirdActivity.java 文件:
//属性动画
public class ThirdActivity extends AppCompatActivity implements View.OnClickListener {
private Button btn_alpha;
private Button btn_translate;
private Button btn_rotate;
private Button btn_scale;
private ImageView iv_show;
ObjectAnimator objectAnimator;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceS
tate);
setContentView(R.layout.activity_third);
initView();
}
private void initView() {
btn_alpha = (Button) findViewById(R.id.btn_alpha);
btn_translate = (Button) findViewById(R.id.btn_translate);
btn_rotate = (Button) findViewById(R.id.btn_rotate);
btn_scale = (Button) findViewById(R.id.btn_scale);
iv_show = (ImageView) findViewById(R.id.iv_show);
btn_alpha.setOnClickListener(this);
btn_translate.setOnClickListener(this);
btn_rotate.setOnClickListener(this);
btn_scale.setOnClickListener(this);
}
评论