自定义VIEW findViewById返回null
搜了好久..尝试了很多方法.
clean没用.
上段代码.
public Brick(Context context,AttributeSet attr) {
super(context);
this.setKeepScreenOn(true);
brick = BitmapFactory.decodeResource(getResources(), R.drawable.brick);
np = new NinePatch(brick, brick.getNinePatchChunk(), null);
sfh = this.getHolder();
sfh.addCallback(this);
paint = new Paint();
paint.setAntiAlias(true);
paint.setColor(Color.WHITE);
paint.setTextSize(25f);
// setFocusable(true);
TypedArray params = context.obtainStyledAttributes(attr,R.styleable.Brick);
letter = new Letter(params.getString(R.styleable.Brick_english),params.getString(R.styleable.Brick_chinese));
就是这出问题鸟~~~~
要同时把
AttributeSet 也传递给父类.
然后就OK了..
浙公网安备 33010602011771号