我使用的是布局类同此:的Android RealtiveLayout不能处理重叠的权
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="5dp"
android:paddingTop="5dp"
android:paddingRight="5dp"
android:paddingBottom="5dp"
android:background="@drawable/list_item_background"
android:descendantFocusability="blocksDescendants"
>
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:textColor="#000000"
android:textSize="35sp"
android:text="18:15" />
<!-- some more views on the right side-->
<RelativeLayout
android:id="@+id/relativeLayoutActive"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_toLeftOf="@id/textView1">
<!-- contains several other views, a RelativeLayout and a FrameLayout-->
</RelativeLayout>
</RelativeLayout>
我现在要在布局上进行两个动画:
- 淡出
relativeLayoutActive
(AlphaAnimation )并将右侧的所有视图翻译为左侧 - 淡入
relativeLayoutActive
并将所有视图重新回到左侧
这里是我的代码,我使用的动画:
public void activate(boolean isActive){
if(!this.active && isActive && checkIfActivatable()){ // start animation 2
if(animating)
return;
animating = true;
animatingActive = isActive;
rootView.addView(relativeLayoutActive);
translate(rootView, clock, true);
fade(relativeLayoutActive, true, 1, 0, null, this, false);
//...
}else if(this.active && !isActive){ // start Animation 1
if(animating)
return;
animating = true;
animatingActive = isActive;
translate(rootView, clock, false);
fade(relativeLayoutActive, false, 1, 0, null, this, false);
//...
view.removeView(relativeLayoutActive);
}
}
private void translate(View targetParent, View target, boolean right){
Animation a = new TranslateAnimation(0.0f,
(right?1:-1)*(targetParent.getWidth() - target.getWidth() - view.getPaddingLeft() -
view.getPaddingRight()), 0.0f, 0.0f);
a.setDuration(500);
a.setInterpolator(AnimationUtils.loadInterpolator(getContext(),
android.R.anim.decelerate_interpolator));
a.setFillAfter(true);
target.startAnimation(a);
}
private void fade(View target, boolean in, float inValue, float outValue, AnimationSet as, AnimationListener listener, boolean useAs){
Animation a = new AlphaAnimation(in?outValue:inValue, in?inValue:outValue);
a.setDuration(500);
a.setFillAfter(true);
if(listener!=null){
a.setAnimationListener(listener);
}
if(!useAs)
target.startAnimation(a);
else{
as.addAnimation(a);
target.startAnimation(as);
}
}
当动画结束“动漫变”是由通过调用view.clearAnimations永久的(),并设置权的LayoutParams。
动画1完美地工作,但2没有。除了relativeLayoutActive
的淡入之外,一切都像它应该那样工作。直到动画结束relativeLayoutActive
变得可见,即在动画期间relativeLayoutActive
不可见。
我想这是因为RelativeLayout
不能处理重叠和自relativeLayoutActive
由视图上的覆盖开始的2至动画结束
我怎样才能解决这个问题它变得不可见的?
关于
你能分享完整的布局文件吗? –