android - Extending a view which overrides onMeasure() -


i have view view1 extends framelayout , overrides onmeasure() this, rendered square:

  @override   protected void onmeasure(int widthmeasurespec, int heightmeasurespec) {     super.onmeasure(widthmeasurespec, widthmeasurespec);   } 

now want create view view2 extends view1, want view2 have height equal parent, , hence cover full screen. of now, square too.

how achieve this?

in view 1:

private boolean measureassquare = true;  @override protected void onmeasure(int widthmeasurespec, int heightmeasurespec) {     if (measureassquare) {         super.onmeasure(widthmeasurespec, widthmeasurespec);     }     else {         super.onmeasure(widthmeasurespec, heightmeasurespec);     } }  public void setmeasureassquare(boolean b) {     measureassquare = b; } 

in view2 constructor subclasses view 1:

public view2(context c) {     setmeasureassquare(false); } 

then can use normal layout weight , height view 2 assign preferred size.


Comments

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

reactjs - React router and this.props.children - how to pass state to this.props.children -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -