唯一的解決辦法,我已經能夠拿出,雖然哈克,仍然有效。
父母是一個RelativeLayout,我有一個隱藏的自定義TextView z位於其他內容上方。當我需要調用動畫時,我爲TextView提供與需要動畫的視圖相同的LayoutParams/background/text,將其設置爲View.VISIBLE,對其進行動畫處理,並在動畫完成時將其設置回View.GONE :
public void doAnimation(final View v){
v.setId(5);
final CustomTextView animatorImage = (CustomTextView) ((MainActivity)mActivity).findViewById(R.id.pick_animator_image); // Our hidden TextView in the FrameLayout
try{
animatorImage.setBackgroundDrawable(v.getBackground());
animatorImage.setText(((TextView)v).getText().toString());
animatorImage.setTextColor(((TextView)v).getCurrentTextColor());
animatorImage.setTextSize(TypedValue.COMPLEX_UNIT_PX, ((TextView)v).getTextSize());
}
catch(Exception e){
}
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(v.getWidth(), v.getHeight());
int[] windowLocation = new int[2];
v.getLocationInWindow(windowLocation);
params.leftMargin = (int) windowLocation[0];
params.topMargin = (int) windowLocation[1] - ((MainActivity)mActivity).getSupportActionBar().getHeight() - getStatusBarHeight(); // Subtract the ActionBar height and the StatusBar height if they're visible
animatorImage.setLayoutParams(params);
animatorImage.setVisibility(View.VISIBLE);
v.setVisibility(View.INVISIBLE);
ScaleAnimation scaleAnim = new ScaleAnimation(1f, 2.5f, 1f, 2.5f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
scaleAnim.setDuration(300);
scaleAnim.setZAdjustment(Animation.ZORDER_TOP);
scaleAnim.setAnimationListener(new AnimationListener(){
public void onAnimationEnd(Animation arg0) {
ScaleAnimation scaleAnim2 = new ScaleAnimation(2.5f, 1f, 2.5f, 1f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
scaleAnim2.setDuration(300);
scaleAnim2.setZAdjustment(Animation.ZORDER_TOP);
scaleAnim2.setAnimationListener(new AnimationListener(){
public void onAnimationEnd(Animation animation) {
animatorImage.clearAnimation();
v.setVisibility(View.VISIBLE);
animatorImage.setVisibility(View.GONE);
}
public void onAnimationRepeat(Animation animation) {
}
public void onAnimationStart(Animation animation) {
}});
animatorImage.startAnimation(scaleAnim2);
}
@Override
public void onAnimationRepeat(Animation animation) {
}
@Override
public void onAnimationStart(Animation animation) {
}});
animatorImage.bringToFront();
animatorImage.startAnimation(scaleAnim);
}
的XML層次是:
RelativeLayout (parent)
ViewGroup (main content body)
TextView (hidden View to animate)
只要改變「R.id.pick_animator_image」到無論你的TextView的ID是在RelativeLayout的,並調用該方法與你想動畫視圖,這會爲你僞裝。
是否解決了此問題?謝謝 – NoobMe
使用hacky解決方案......我基本上將父級佈局更改爲FrameLayout,並將隱藏的Custom TextView z-放置在其他內容的上方。當我需要調用動畫時,我爲TextView提供與需要動畫的視圖相同的LayoutParams/background/text,將其設置爲View.VISIBLE,對其進行動畫處理,並在動畫完成時將其設置回View.GONE 。我會在下面回答我的猜測 – Guardanis