【发布时间】:2014-07-03 10:06:59
【问题描述】:
我需要动画方面的帮助。 (我的观点更复杂,我只向您展示我的布局 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>
我想显示和隐藏一些视图:
- 没有可见的视图
- topLeft 和 topRight 从边缘(topLeft 从左侧,topRight 从右侧)移到屏幕中心(父级)。
- 当 topLeft 和 topRight 达到其移动的一半时,bottomLeft 和 bottomRight 显示与上一步中的 topLeft 和 topRight 完全相同
- 所有四个视图都保持可见几秒钟。
- topLeft 和 topRight 从屏幕中心(父级)移到边缘(topLeft 到左,topRight 到右)。
- 当 topLeft 和 topRight 达到其移动的一半时,bottomLeft 和 bottomRight 移出与上一步中的 topLeft 和 topRight 完全相同
- 当所有视图消失时,一个BigView 从左边缘移动并填满屏幕。
- oneBigView 会停留几秒钟。
- oneBigView 从屏幕中心移动到左边缘。
- 当 oneBigView 消失时,一切都从 1 开始。
我试过这样做,但总是有问题:
- 我尝试添加一些翻译动画并更改可见性(我尝试了 View.INVISIBLE 和 VIEW.GONE)onAnimationEnd:
显示
<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);
}
});
等等......它非常适合可见性,但动画一点也不流畅(大部分时间它就像我没有使用动画一样工作)。当我停止更改可见性时,动画可以正常工作,但不能正常工作。
有什么想法吗?
【问题讨论】:
标签: android android-layout android-animation