Android 向上滑动动画无法正常工作
我有一个线性布局Android 向上滑动动画无法正常工作,android,android-animation,android-linearlayout,Android,Android Animation,Android Linearlayout,我有一个线性布局 <LinearLayout xmlns:card_view="http://schemas.android.com/apk/res-auto" android:id="@+id/card_view" android:layout_width="match_parent" android:layout_height="wrap_cont
<LinearLayout
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="@+id/card_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:orientation="vertical"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="-4dp">
<android.support.v4.widget.NestedScrollView
android:id="@+id/scrollView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fillViewport="true">
<LinearLayout
android:id="@+id/paper_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusableInTouchMode="true"
android:background="#ffffff"
android:orientation="vertical">
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="26dp"
android:src="@mipmap/ic_app_icon" />
<TextView
android:id="@+id/company_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:gravity="center"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:singleLine="true"
android:text="Company Name"
android:textColor="@android:color/black"
android:textSize="30dp" />
<TextView
android:id="@+id/company_address"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:gravity="center"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:singleLine="true"
android:text="Company Address"
android:textColor="@android:color/black"
android:textSize="14dp" />
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="6dp"
android:layout_marginRight="6dp"
android:layout_marginTop="10dp"
android:focusableInTouchMode="false"
android:listSelector="#00000000"
android:overScrollMode="never"
android:scrollbars="none" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:layout_marginRight="15dp"
android:layout_marginTop="10dp"
android:src="@mipmap/test_img" />
<View
android:layout_width="match_parent"
android:layout_height="16dp" />
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
</LinearLayout>
我试着这样开始动画
if (slide != null) {
linearLayout.startAnimation(slide);
slide.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
}
@Override
public void onAnimationRepeat(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
linearLayout.clearAnimation();
startActivity(MainActivity.class);
}
});
}
我的目标是在动画完成后立即开始另一项活动
public void startActivity(Class<?> cls) {
Intent intent = new Intent(this, cls);
startActivity(intent);
overridePendingTransition(R.anim.fadein, R.anim.fadeout);
}
public void startActivity(类别cls){
意向意向=新意向(本,cls);
星触觉(意向);
覆盖转换(R.anim.fadein,R.anim.fadeout);
}
但是,4秒钟后,当动画完成时,新活动不会立即工作。有没有办法加快调用新活动的速度?尝试使用以下方法:
val animation = ObjectAnimator.ofFloat(layout, "translationY", 440f)
animation.duration = 4500
animation.interpolator = LinearInterpolator()
animation.addListener(AnimatorListenerAdapter() {
//animation end is here
// TODO
})
代码在kotlin中,但您可以轻松转换它在启动动画之前添加侦听器我更改了它,但仍然无法工作@Lucanicoletti调试它了吗,代码是否通过
startActivity
调用运行?我更改了它,但仍然有相同的错误。我认为问题在于TranslateAnimation@Luca Nicoletty中的某个地方您的动画是自上而下的@Luca Nicolettigive为负值
val animation = ObjectAnimator.ofFloat(layout, "translationY", 440f)
animation.duration = 4500
animation.interpolator = LinearInterpolator()
animation.addListener(AnimatorListenerAdapter() {
//animation end is here
// TODO
})