当用户点击捕获按钮时,我想制作像fadeIn-fadeOut这样的动画。 当我在animatedView和android上设置alpha 1.0时:fromAlpha =“1.0”,android:toAlpha =“0.0”它可以工作,但我需要反转它。 这是我的布局:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<SurfaceView
android:id="@+id/preview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<View
android:id="@+id/animated_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/black"
android:alpha="0.0"/>
<Button
android:id="@+id/button_capture"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_centerVertical="true" />
</RelativeLayout>
这是我的动画xml:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/accelerate_interpolator">
<alpha
android:duration="500"
android:fromAlpha="0.0"
android:repeatCount="1"
android:repeatMode="reverse"
android:toAlpha="1.0"
/>
</set>
这就是我如何运行它:
animClick = AnimationUtils.loadAnimation(getApplicationContext(),
R.anim.click);
@OnClick(R.id.button_capture)
void onCaptureClick() {
camera.takePicture(null, null, jpegCallback);
animatedView.startAnimation(animClick);
}
没有任何反应,我做错了什么?
答案 0 :(得分:0)
设置动画并不是一个问题,你没有正确安排你的布局 请看一下布局,只要它不是你想要的,但你将能够理解你将如何解决它。
你输高度==&gt;每个东西的match_parent可能是你无法为视图设置动画的原因。 <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<SurfaceView
android:id="@+id/preview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<View
android:id="@+id/animated_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@mipmap/ic_launcher"
/>
<Button
android:id="@+id/button_capture"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_centerVertical="true" />
</RelativeLayout>
你可以使用更新的xml在这里工作正常!!!