一段时间以来,我一直在努力为这个问题找到一个好的解决方案,但一直无法引用。。。所以,希望有人能帮助我,或者给我指明正确的方向,因为我已经用完了明年的谷歌配额。
基本上,我想完成的是一个单独视图的ScaleAnimation,当长时间单击时,它将展开,然后收缩,表示它已被按下。
这就是全部设置;没有问题。
问题是ScaleAnimation被视图的父对象剪裁,并且没有延伸到其父对象中。以下是层次结构:
Relative >
Relative >
Linear > (<-- The animation is cut at the outer bounds of this parent)
View
我尝试过添加android:clipChildren="false"和android:clifpPadding="false),但这两种解决方案都没有帮助我在第一个家长的边界之外进行动画制作。
我知道tween Animations的设计目的是不扩展到动画视图所在的视图的边界之外,但这是不可能的吗?
还是我完全错了?
如何在第一个父对象的边界之外设置动画?
提前感谢您的帮助,-Matt
我唯一能想到的解决方案,尽管很粗糙,但仍然有效。
父项是RelativeLayout,我有一个隐藏的自定义文本视图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"更改为RelativeLayout中TextView的id,并用您想要设置动画的视图调用该方法,这将为您伪造它。