我使用的是佈局類同此:的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至動畫結束
我怎樣才能解決這個問題它變得不可見的?
關於
你能分享完整的佈局文件嗎? –