android studio中布局怎么预览不了(已解决)

我们在android studio中新建了一个项目

想预览一下布局,但是却无法预览

preview is unavailable until a successful build 

这说明没有进行build

所以需要构建项目一下才可以

耐心等待下,就会出现

发布了159 篇原创文章 · 获赞 26 · 访问量 7万+
展开阅读全文

自定义view使用动画的问题

04-18

最近在学习自定义view相关的东西,想实现一个画圆的动画,但是始终没有效果,代码如下: ``` public class AnimatorView extends View { private static final String TAG = "AnimatorView"; private Paint mPaint; private RectF mArcRectF; private ObjectAnimator mProgressAnim; private int mProgress = 0; public AnimatorView(Context context) { this(context, null); } public AnimatorView(Context context, AttributeSet attrs) { this(context, attrs, 0); } public AnimatorView(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); init(); initAnimator(); } private void init() { if(mPaint == null) mPaint = new Paint(); setLayerType(View.LAYER_TYPE_SOFTWARE, null); mPaint.setAntiAlias(true); mPaint.setStyle(Paint.Style.STROKE); mPaint.setColor(Color.RED); mPaint.setStrokeWidth(16); } private void initAnimator() { mProgressAnim = ObjectAnimator.ofInt(this, "progress", 0, 360); mProgressAnim.setDuration(5000); mProgressAnim.setInterpolator(null); } public int getProgress() { return mProgress; } public void setProgress(int progress) { mProgress = progress; invalidate(); } @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { super.onMeasure(widthMeasureSpec, heightMeasureSpec); int width = MeasureSpec.getSize(widthMeasureSpec); int height = MeasureSpec.getSize(heightMeasureSpec); int centerX = width / 2; int centerY = height / 2; int offset = Math.min(centerX, centerY) / 2; mArcRectF = new RectF(centerX - offset, centerY - offset, centerX + offset, centerY + offset); } @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); Log.d(TAG, "onDraw() ---> mProgress=" + mProgress); canvas.drawArc(mArcRectF, 90, mProgress, false, mPaint); mProgressAnim.start(); } } ``` 我的想法是通过mProgress来逐渐的将圆弧扩大,但实际效果是这个值一直为0,这个属性动画还是没搞明白 问答

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 技术黑板 设计师: CSDN官方博客

分享到微信朋友圈

×

扫一扫,手机浏览