All Projects → youlookwhat → CustomViewStudy

youlookwhat / CustomViewStudy

Licence: other
This repository is used to learn CustomView(Text、Image、Progress、ViewGroup、ViewGragHelper).

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to CustomViewStudy

double-avatar-view
Instagram-like double avatar view with cropping
Stars: ✭ 31 (-59.21%)
Mutual labels:  custom-view
iiVisu
A player/ recorder visualizer with the swipe to seek functionality.
Stars: ✭ 112 (+47.37%)
Mutual labels:  custom-view
PassCodeText
A customised EditText view serving the purpose of taking numeric One Time Password from a user. With stunning animation, and high customizability.
Stars: ✭ 105 (+38.16%)
Mutual labels:  custom-view
clearable-edittext
Simple custom view for clearable EditText.
Stars: ✭ 58 (-23.68%)
Mutual labels:  custom-view
RecyclerViewCardGallery
RecyclerView实现循环banner,替代ViewPager方案。能够快速滑动并最终定位到居中位置(相比于原库支持了循环滑动)
Stars: ✭ 610 (+702.63%)
Mutual labels:  custom-view
TextButton
⏹️ An easy to use `TextButton` when you need a TextView-like button, with handy touch feedback effects.
Stars: ✭ 19 (-75%)
Mutual labels:  custom-view
MarkDEditor
A WYSIWYG MarkDown editor for Android.
Stars: ✭ 76 (+0%)
Mutual labels:  custom-view
SuperBadge
🚀 📛 SuperBadge Android Library 🔥
Stars: ✭ 34 (-55.26%)
Mutual labels:  custom-view
PlaceholderTextView
A custom TextView which shows placeholder lines given a sample text when it has no text set
Stars: ✭ 24 (-68.42%)
Mutual labels:  custom-view
MutativeFab
This is animating floating action button with text
Stars: ✭ 54 (-28.95%)
Mutual labels:  custom-view
EasyMoney-Widgets
The widgets (EditText and TextView) for support of money requirements like currency, number formatting, comma formatting etc.
Stars: ✭ 91 (+19.74%)
Mutual labels:  custom-view
mCustomView
总结了博主这么多年所写的自定义view,以及自定义view的教程
Stars: ✭ 17 (-77.63%)
Mutual labels:  custom-view
CustomFormViews
A clean collection of views used for forms.
Stars: ✭ 12 (-84.21%)
Mutual labels:  custom-view
RxLoading
RxJava library for showing a loading (i.e. progress bar) state while waiting for async data with minimal effort and advanced options.
Stars: ✭ 49 (-35.53%)
Mutual labels:  custom-view
WaveView
Simple Android library to draw sinusoidal waves.
Stars: ✭ 43 (-43.42%)
Mutual labels:  custom-view
un-material-tab
(deprecated) Custom tab layout which can be used as a material TabLayout alternative and contains basic functionality which Google's TabLayout has.
Stars: ✭ 83 (+9.21%)
Mutual labels:  custom-view
RoundCornerProgress
No description or website provided.
Stars: ✭ 14 (-81.58%)
Mutual labels:  custom-view
auto-fill-edit-text
This custom EditText can suggest and fill text defined before.
Stars: ✭ 26 (-65.79%)
Mutual labels:  custom-view
signal-strength-view
📶 Material design signal strength view for Android
Stars: ✭ 30 (-60.53%)
Mutual labels:  custom-view
android-tableview-kotlin
Android's missing TableView component.
Stars: ✭ 40 (-47.37%)
Mutual labels:  custom-view

CustomViewStudy

主要参照Hongyang的CSDN博客所写,具体细节优化请见这里。如有错误欢迎指正,如有侵权,请联系我删除。

Blog Catalogue

Source Code

Picture

Code Optimization

1. CustomTitleView优化

1.1 关于文字显示优化:

//             int textWidth = mRect.width(); // 这样mRect.width()直接计算出来的会有误差
               float textWidth = mPaint.measureText(mTitleText);

//              int textHeight = mRect.height(); //直接计算出来的会有误差
                Paint.FontMetrics fontMetrics = mPaint.getFontMetrics();
                float textHeight = Math.abs((fontMetrics.bottom - fontMetrics.top));

1.2 onDraw里画Text时起点坐标优化:

canvas.drawText(mTitleText, getWidth() / 2 - mRect.width() / 2 - mRect.left, getHeight() / 2 + mRect.height() / 2, mPaint);

canvas.drawText(String text,float x,float y,Paint paint); x和y是绘制时的起点坐标(左下角);

" - mRect.left": 就很标准,居中显示(csdn:yql_running解决)

2. 圆环交替 等待效果优化

2.1 新开线程画线,离开页面时线程未关闭优化

// 用来开关线程
    private boolean isContinue;
    
    // 绘图线程
        new Thread() {
            public void run() {
                while (isContinue) {
                    mProgress++;
                    if (mProgress == 360) {
                        mProgress = 0;
                        isNext = !isNext;
                    }
                    Log.e("--------", "在执行..");
                    postInvalidate();

                    try {
                        Thread.sleep(100 / mSpeed);// 这里优化了一下,值越大,速度越快
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }

            }
        }.start();

Activity相关代码:

@Override
    protected void onStop() {
        super.onStop();
        customProgressBar01.setContinue(false);
        customProgressBar02.setContinue(false);
        customProgressBar03.setContinue(false);
    }

2.2 用户宽高若设置wrap_content时优化

@Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
//        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
        int modeWidth = MeasureSpec.getMode(widthMeasureSpec);
        int sizeWidth = MeasureSpec.getSize(widthMeasureSpec);

        if (modeWidth == MeasureSpec.EXACTLY) {
            width = sizeWidth;
        } else {//默认宽度200dp
            width = (int) getContext().getResources().getDimension(R.dimen.width);
        }
        Log.e("------------->", "width:" + width);
        setMeasuredDimension(width, width);
    }

Download

Reference

Thanks

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].