这是current behaviour. 我希望椭圆视图与动画视图重叠。 '肩膀'需要隐藏在椭圆形视图中。
我已经在使用FrameLayout,并且还尝试使用ChildToFront,使用翻译,提升但似乎没有任何效果。
如果您需要更多详细信息以了解问题,请告知我们。
布局:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/parentLinearLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/id_face" />
<a.b.c.OvalAnimationView
android:layout_width="match_parent"
android:layout_height="match_parent" />
</FrameLayout>
绘制逻辑:
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
if (w != 0 && h != 0) {
if (horizontalMargin == 0) {
horizontalMargin = getMeasuredWidth() / WIDTH_FACTOR;
}
if (verticalMargin == 0) {
verticalMargin = 0.11f * getMeasuredHeight();
}
fullScreenRect = new Rect(0, 0, getMeasuredWidth(), getMeasuredHeight());
firstArc = new RectF(
horizontalMargin,
verticalMargin,
getMeasuredWidth() - horizontalMargin,
getMeasuredHeight() - verticalMargin);
secondArc = new RectF(
horizontalMargin,
verticalMargin,
getMeasuredWidth() - horizontalMargin,
getMeasuredHeight() - verticalMargin);
}
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
canvas.drawArc(firstArc, 0, 360, true, borderPaint);
canvas.drawArc(secondArc,0, 360, true, eraser);
}
public void init(int borderColor) {
this.horizontalMargin = 0;
this.verticalMargin = 0;
borderPaint = new Paint();
borderPaint.setColor(borderColor);
borderPaint.setStrokeWidth(35);
borderPaint.setStyle(Paint.Style.STROKE);
eraser = new Paint();
eraser.setColor(Color.TRANSPARENT);
eraser.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_OUT));
eraser.setAntiAlias(true);
}
动画:
private void moveViewToScreenCenter( View view )
{
DisplayMetrics dm = new DisplayMetrics();
getActivity().getWindowManager().getDefaultDisplay().getMetrics(dm);
int statusBarOffset = dm.heightPixels - lLayout.getMeasuredHeight();
int originalPos[] = new int[2];
view.getLocationOnScreen( originalPos );
int xDest = dm.widthPixels/2;
xDest -= (view.getMeasuredWidth()/2);
int yDest = dm.heightPixels/2 - (view.getMeasuredHeight()/2) - statusBarOffset;
AnimationSet animSet = new AnimationSet(true);
animSet.setFillAfter(true);
animSet.setDuration(2500);
animSet.setInterpolator(new AccelerateInterpolator());
TranslateAnimation translateAnimation = new TranslateAnimation( 0, xDest - originalPos[0] , 0, yDest - originalPos[1]);
animSet.addAnimation(translateAnimation);
ScaleAnimation scaleAnimation = new ScaleAnimation(1.0f, 0.70f, 1.0f, 0.70f, ScaleAnimation.RELATIVE_TO_PARENT, .5f, ScaleAnimation.RELATIVE_TO_PARENT, .4f);
animSet.addAnimation(scaleAnimation);
animSet.setZAdjustment(-1);
new Handler().postDelayed(new Runnable() {
public void run() {
iFaceListener.onFaceAnimationFinished();
}
}, animSet.getDuration());
view.startAnimation(animSet);
}
答案 0 :(得分:2)
我自己修正了。
后验性代码:
public class OvalAnimationView extends View {
private Paint transparentPaint = new Paint();
private Paint tPaint = new Paint();
private Paint eraser = new Paint();
private Paint borderPaint = new Paint();
private float horizontalMargin;
private float verticalMargin;
private Canvas temp;
private float WIDTH_FACTOR = 15f;
private Rect fullScreenRect;
private RectF firstArc, secondArc;
private Bitmap bitmap;
public OvalAnimationView(Context context) {
super(context);
}
public OvalAnimationView(Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
}
public OvalAnimationView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
setLayerType(LAYER_TYPE_SOFTWARE, null);
}
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
if (w != 0 && h != 0) {
if (horizontalMargin == 0) {
horizontalMargin = getMeasuredWidth() / WIDTH_FACTOR;
}
if (verticalMargin == 0) {
verticalMargin = 0.11f * getMeasuredHeight();
}
fullScreenRect = new Rect(0, 0, getMeasuredWidth(), getMeasuredHeight());
firstArc = new RectF(
horizontalMargin,
verticalMargin,
getMeasuredWidth() - horizontalMargin,
getMeasuredHeight() - verticalMargin);
secondArc = new RectF(
horizontalMargin,
verticalMargin,
getMeasuredWidth() - horizontalMargin,
getMeasuredHeight() - verticalMargin);
}
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
}
public void init(int borderColor) {
this.horizontalMargin = 0;
this.verticalMargin = 0;
temp = new Canvas();
transparentPaint = new Paint();
transparentPaint.setColor(Color.BLACK);
transparentPaint.setStyle(Paint.Style.FILL);
tPaint = new Paint();
tPaint.setColor(Color.TRANSPARENT);
tPaint.setStyle(Paint.Style.FILL);
borderPaint = new Paint();
borderPaint.setColor(borderColor);
borderPaint.setStrokeWidth(35);
borderPaint.setStyle(Paint.Style.STROKE);
}
@Override
protected void dispatchDraw(Canvas canvas) {
super.dispatchDraw(canvas);
if (bitmap == null) {
createWindowFrame();
}
canvas.drawBitmap(bitmap, 0, 0, null);
}
protected void createWindowFrame() {
bitmap = Bitmap.createBitmap(getWidth(), getHeight(), Bitmap.Config.ARGB_8888);
Canvas osCanvas = new Canvas(bitmap);
RectF outerRectangle = new RectF(0, 0, getWidth(), getHeight());
osCanvas.drawRect(fullScreenRect, transparentPaint);
Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
paint.setColor(Color.TRANSPARENT);
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_OUT));
float centerX = getWidth() / 2;
float centerY = getHeight() / 2;
float radius = 50;
osCanvas.drawCircle(centerX, centerY, radius, paint);
osCanvas.drawArc(firstArc, 0, 360, true, paint);
}
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
super.onLayout(changed, l, t, r, b);
bitmap = null;
}
}