我需要动画方面的帮助。 (我的观点更复杂,我只向您展示我的布局 xml 的主要元素)
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true" >
<LinearLayout
android:id="@+id/oneBigView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerVertical="true"
android:gravity="center_vertical"
android:orientation="vertical">
</LinearLayout>
<LinearLayout
android:id="@+id/fourSmallViews"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:gravity="center_vertical"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weightSum="2" >
<RelativeLayout
android:id="@+id/topLeft"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1" >
</RelativeLayout>
<RelativeLayout
android:id="@+id/topRight"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1">
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="invisible"
android:weightSum="2" >
<RelativeLayout
android:id="@+id/bottomLeft"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1" >
</RelativeLayout>
<RelativeLayout
android:id="@+id/bottomRight"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1" >
</RelativeLayout>
</LinearLayout>
</LinearLayout>
</RelativeLayout>
我想显示和隐藏一些 View :
- 没有可见的 View
- topLeft 和 topRight 从边缘(topLeft 从左边,topRight 从右边)移到屏幕中心(父级)。
- 当 topLeft 和 topRight 移动一半时 bottomLeft 和 bottomRight 显示与上一步中的 topLeft 和 topRight 完全相同
- 所有四个 View 都保持可见几秒钟。
- topLeft 和 topRight 从屏幕中心(父级)移出到边缘(topLeft 到左,topRight 到右)。
- 当 topLeft 和 topRight 移动一半时 bottomLeft 和 bottomRight 移出与上一步中的 topLeft 和 topRight 完全相同
- 当所有 View 消失时,一个 BigView 从左边缘移动并填满屏幕。
- oneBigView 停留几秒钟。
- oneBigView 从屏幕中心移动到左边缘。
- 当 oneBigView 消失时,一切从 1 重新开始。
我试过这样做,但总是有些地方不对:
- 我尝试在动画结束时添加一些翻译动画并更改可见性(我尝试了 View.INVISIBLE 和 VIEW.GONE):
显示
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/decelerate_interpolator">
<translate
android:fromXDelta="-100%p"
android:toXDelta="0"
android:duration="500" />
</set>
隐藏
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/decelerate_interpolator">
<translate
android:fromXDelta="0"
android:toXDelta="-100%p"
android:duration="500" />
</set>
.java
final Animation leftIn=AnimationUtils.loadAnimation(this, R.anim.show);
final Animation leftOut=AnimationUtils.loadAnimation(this, R.anim.hide);
leftIn.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
// TODO Auto-generated method stub
//start animation for showing topRight bottomLeft and bottomRight
//with propper startOffset
}
@Override
public void onAnimationRepeat(Animation animation) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationEnd(Animation animation) {
// TODO Auto-generated method stub
left1.setVisibility(View.VISIBLE);
leftOut.setStartOffset(4000);
left1.startAnimation(leftOut);
}
});
leftOut.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationRepeat(Animation animation) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationEnd(Animation animation) {
// TODO Auto-generated method stub
left1.setVisibility(View.INVISIBLE);
}
});
等等...它的可见性非常好,但动画一点也不流畅(大多数时候它就像我没有使用动画一样工作)。当我停止更改可见性时,动画可以正常工作,但无法完成工作。
有什么想法吗?
最佳答案
您可以尝试更改 View 的 alpha 值,而不是使其不可见或消失。
关于用于隐藏 View 而不改变可见性的 Android 翻译动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24550752/