img_ayout_1和img_ayout_2是俩布局
public Runnable runnable = new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
//俩个动画
AnimationSet animationSet1 = new AnimationSet(true);
AnimationSet animationSet2 = new AnimationSet(true);
//设置imageView2 为可见
img_ayout_2.setVisibility(0);
TranslateAnimation ta = new TranslateAnimation(
Animation.RELATIVE_TO_SELF, -1f,
Animation.RELATIVE_TO_SELF,0f,
Animation.RELATIVE_TO_SELF, 0f,
Animation.RELATIVE_TO_SELF, 0f);
//设置动画持续时间
ta.setDuration(10000);
//放入动画
animationSet1.addAnimation(ta);
//动画充满
animationSet1.setFillAfter(true);
ta = new TranslateAnimation(
Animation.RELATIVE_TO_SELF,0f,
Animation.RELATIVE_TO_SELF, 1.0f,
Animation.RELATIVE_TO_SELF,0f,
Animation.RELATIVE_TO_SELF, 0f);
ta.setDuration(10000);
animationSet2.addAnimation(ta);
animationSet2.setFillAfter(true);
// 开始执行
img_ayout_1.startAnimation(animationSet1);
img_ayout_2.startAnimation(animationSet2);
if (juage){
handler.postDelayed(runnable,8000);
}
}
};
调用:handler.postDelayed(runnable, 0);
问题:在切换下一轮动画的时候俩布局间距会变大
布局:
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_weight="0.14"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:orientation="vertical"
android:id="@+id/img_Layout_1"
>
<ImageView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/line1" />
<ImageView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/line2" />
</RelativeLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:id="@+id/img_Layout_2"
android:orientation="vertical" >
<ImageView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/line1" />
<ImageView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/line2" />
</RelativeLayout>