PackageLiu.myrecyleviewchoosephoto.view;ImportAndroid.content.Context;ImportAndroid.util.AttributeSet;Importandroid.widget.RelativeLayout;/*** Square relativelayout * Created by Liu Nan on 2016/8/13 0013.16:07*/ Public classSquarerelativelayoutextendsRelativelayout { PublicSquarerelativelayout (Context context) {Super(context); } PublicSquarerelativelayout (Context context, AttributeSet attrs) {Super(context, attrs); } PublicSquarerelativelayout (context context, AttributeSet attrs,intdefstyleattr) { Super(context, attrs, defstyleattr); } @Overrideprotected voidOnmeasure (intWidthmeasurespec,intHeightmeasurespec) { //set your own measurement resultsSetmeasureddimension (Getdefaultsize (0,widthmeasurespec), getdefaultsize (0, Heightmeasurespec)); /*** Measure sub-view*/ intChildwidthsize=getmeasuredwidth (); //the height is the same as the widthWidthmeasurespec =Measurespec.makemeasurespec (childwidthsize,measurespec.exactly); Heightmeasurespec=Widthmeasurespec; Super. Onmeasure (Widthmeasurespec, Heightmeasurespec); }}
android-a square container