第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定

代碼沒(méi)有錯(cuò)誤,但是運(yùn)行后總是已經(jīng)停止,在1-4 自定義底部View這一節(jié)內(nèi),前面的都可以運(yùn)行出來(lái)

java.lang.NullPointerException
Exception?details?are?logged?in?Window?>?Show?View?>?Error?Log

java.lang.NullPointerException
????at?com.example.weixin.ChangeColorIconWithText.onDraw(ChangeColorIconWithText.java:85)
????at?android.view.View.draw(View.java:14465)
????at?android.view.View.draw(View.java:14350)
????at?android.view.ViewGroup.drawChild(ViewGroup.java:3103)
????at?android.view.ViewGroup.dispatchDraw(ViewGroup.java:2940)
????at?android.view.View.draw(View.java:14468)
????at?android.view.View.draw(View.java:14350)
????at?android.view.ViewGroup.drawChild(ViewGroup.java:3103)
????at?android.view.ViewGroup.dispatchDraw(ViewGroup.java:2940)
????at?android.view.View.draw(View.java:14348)
????at?android.view.ViewGroup.drawChild(ViewGroup.java:3103)
????at?android.view.ViewGroup.dispatchDraw(ViewGroup.java:2940)
????at?android.view.View.draw(View.java:14348)
????at?android.view.ViewGroup.drawChild(ViewGroup.java:3103)
????at?android.view.ViewGroup.dispatchDraw(ViewGroup.java:2940)
????at?android.view.View.draw(View.java:14468)
????at?android.view.View.draw(View.java:14350)
????at?android.view.ViewGroup.drawChild(ViewGroup.java:3103)
????at?android.view.ViewGroup.dispatchDraw(ViewGroup.java:2940)
????at?android.view.View.draw(View.java:14468)
????下面是代碼:
????package?com.example.weixin;

import?android.content.Context;
import?android.content.res.TypedArray;
import?android.graphics.Bitmap;
import?android.graphics.Canvas;
import?android.graphics.Paint;
import?android.graphics.Rect;
import?android.graphics.drawable.BitmapDrawable;
import?android.util.AttributeSet;
import?android.util.TypedValue;
import?android.view.View;

public?class?ChangeColorIconWithText?extends?View?{
	private?int?mColor?=?0xFF45C01A;
	private?Bitmap?mIconBitmap;
	private?String?mTextString?=?"微信";
	private?int?mTextSize?=?(int)?TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP,?12,?
			getResources().getDisplayMetrics());
	
	private?Canvas?mCanvas;
	private?Bitmap?mBitmap;
	private?Paint?mPaint;
	
	private?float?mAlpha;

	private?Rect?mIconRect;
	private?Rect?mTextBound;
	private?Paint?mTextPaint;
	
	public?ChangeColorIconWithText(Context?context,?AttributeSet?attrs,
			int?defStyleAttr)?{
		super(context,?attrs,?defStyleAttr);
		TypedArray?a?=?context.obtainStyledAttributes(attrs,?
				R.styleable.ChangeColorIconWithText);
		int?n?=?a.getIndexCount();
		for?(int?i?=?0;?i?<?n;?i++)?{
			int?attr?=?a.getIndex(i);
			switch?(attr)?{
			case?R.styleable.ChangeColorIconWithText_icon1:
				BitmapDrawable?drawable?=?(BitmapDrawable)?a.getDrawable(attr);
				mIconBitmap?=?drawable.getBitmap();
				break;

			case?R.styleable.ChangeColorIconWithText_color:
				mColor?=?a.getColor(attr,?0xFF45C01A);
				break;
			case?R.styleable.ChangeColorIconWithText_text:
				mTextString?=?a.getString(attr);
				break;
			case?R.styleable.ChangeColorIconWithText_text_size:
				mTextSize?=?(int)?a.getDimension(attr,?
						TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP,?
								12,?getResources().getDisplayMetrics()));
				break;
			}
		}
		a.recycle();
		
		mTextBound?=?new?Rect();
		mTextPaint?=?new?Paint();
		mTextPaint.setTextSize(mTextSize);
		mTextPaint.setColor(0Xff555555);	
		mTextPaint.getTextBounds(mTextString,?0,?mTextString.length(),?mTextBound);
	}
	
	@Override
	protected?void?onMeasure(int?widthMeasureSpec,?int?heightMeasureSpec)?{
		//?TODO?Auto-generated?method?stub
		super.onMeasure(widthMeasureSpec,?heightMeasureSpec);
		int?iconWidth?=?Math.min(getMeasuredWidth()-
				getPaddingLeft()-getPaddingRight(),?
				getMeasuredHeight()-getPaddingTop()-
				getPaddingBottom()-?mTextBound.height());
		int?left?=?getMeasuredWidth()/2?-?iconWidth/2;
		int?top?=?(getMeasuredHeight()-mTextBound.height())/2
				-iconWidth/2;
		mIconRect?=?new?Rect(left,?top,?left+iconWidth,?
				top+iconWidth);
	}
	
	protected?void?onDraw(Canvas?canvas)?{
		//?TODO?Auto-generated?method?stub
		super.onDraw(canvas);
		mCanvas.drawBitmap(mIconBitmap,?mIconRect,?mIconRect,?null);
		
		
	}

	public?ChangeColorIconWithText(Context?context,?AttributeSet?attrs)?{
		this(context,attrs,0);
		//?TODO?Auto-generated?constructor?stub
	}

	public?ChangeColorIconWithText(Context?context)?{
		this(context,null);
		//?TODO?Auto-generated?constructor?stub
	}

}


正在回答

1 回答

求解答??!

0 回復(fù) 有任何疑惑可以回復(fù)我~

舉報(bào)

0/150
提交
取消
微信6.0主界面
  • 參與學(xué)習(xí)       58943    人
  • 解答問(wèn)題       188    個(gè)

本課程將講解微信6.0主界面的實(shí)現(xiàn)方法,微信5.2.1后續(xù)課程

進(jìn)入課程

代碼沒(méi)有錯(cuò)誤,但是運(yùn)行后總是已經(jīng)停止,在1-4 自定義底部View這一節(jié)內(nèi),前面的都可以運(yùn)行出來(lái)

我要回答 關(guān)注問(wèn)題
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)