Skip to content

Commit

Permalink
Summary: add onMeasure process
Browse files Browse the repository at this point in the history
  • Loading branch information
hailang.jiang committed Jun 20, 2017
1 parent 3412fe4 commit 8ac00dc
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 24 additions & 0 deletions app/src/main/java/rich/ivan/monthbill/MonthBillView.java
Expand Up @@ -8,6 +8,7 @@
import android.graphics.Path;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;

/**
Expand All @@ -16,6 +17,7 @@
*/

public class MonthBillView extends View {
private static final String TAG = "MonthBillView";

private int[] mMonthArray;
private double[] mBillValues;
Expand Down Expand Up @@ -141,6 +143,28 @@ protected void onSizeChanged(int w, int h, int oldw, int oldh) {
mBillRange = (mBillRange == 0 ? 1 : mBillRange);
}

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int widthMode = MeasureSpec.getMode(widthMeasureSpec);
int widthSize = MeasureSpec.getSize(widthMeasureSpec);

int heightMode = MeasureSpec.getMode(heightMeasureSpec);
int heightSize = MeasureSpec.getSize(heightMeasureSpec);

Paint.FontMetrics fontMetrics = mTextPaint.getFontMetrics();
float fontHeight = fontMetrics.descent - fontMetrics.ascent;

mWidth = widthSize;

if (heightMode == MeasureSpec.EXACTLY) {
mHeight = heightSize;
} else {
mHeight = (int) (4 * fontHeight + 4 * fontHeight + getPaddingTop() + getPaddingBottom());
}

setMeasuredDimension(mWidth, mHeight);
}

@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/activity_main.xml
Expand Up @@ -10,7 +10,7 @@
<rich.ivan.monthbill.MonthBillView
android:id="@+id/month_bill_view"
android:layout_width="match_parent"
android:layout_height="150dp"/>
android:layout_height="wrap_content"/>

<TextView
android:layout_width="match_parent"
Expand Down

0 comments on commit 8ac00dc

Please sign in to comment.