gpt4 book ai didi

android - 动画 View 在椭圆 View 后面转换

转载 作者:搜寻专家 更新时间:2023-11-01 09:28:23 25 4
gpt4 key购买 nike

这是 current behaviour.我希望椭圆 View 与动画 View 重叠。 “肩膀”需要隐藏在椭圆形 View 中。

我已经在使用 FrameLayout 并尝试将 bringChildToFront、使用平移、提升但似乎没有任何效果。

如果您需要更多详细信息以更全面地了解问题,请告诉我。

布局:

<?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);
}

最佳答案

我自己修好了。

后验代码:

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;
}
}

关于android - 动画 View 在椭圆 View 后面转换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49321982/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com