Inheritance ConstraintLayout

The development of complex layouts can be basically achieved by ConstraintLayout, so we inherit ConstraintLayout achieve a EasyConstraintLayout can add rounded corners and shadow effects for the child view.

public class EasyConstraintLayout extends ConstraintLayout {
public EasyConstraintLayout(Context context, AttributeSet attrs) {
super(context, attrs);
}

@Override
public LinearLayout.LayoutParams generateLayoutParams(AttributeSet attrs) {
return new LayoutParams(getContext(), attrs);
}

@Override
protected Boolean checkLayoutParams (ViewGroup.LayoutParams P) {
return the instanceof LayoutParams for P;
}
}
. 1
2
. 3
. 4
. 5
. 6
. 7
. 8
. 9
10
. 11
12 is
13 is
14
15
to rewrite the two methods, we use these methods to achieve sub-view from read Definition property, before you want to customize some of the attributes in xml

<? xml Version = "1.0" encoding = "UTF-8"?>
<Resources>
<-! In order to facilitate the expansion of other layout, defined in the outer layer, named after the beginning of the layout_, or lint will be reported red warning ->
< attr name = "layout_radius" the format = "Dimension" />
<attr name = "layout_shadowColor" the format = "Color" />
<attr name = "layout_shadowEvaluation" the format = "Dimension" />
<attr name = "layout_shadowDx" the format = "Dimension" />
<attr name = "layout_shadowDy" the format = "Dimension" />
<-! a unified EasyLayout, for packaging read custom attributes ->
<DECLARE-styleable name = "EasyLayout">
< name = attr "layout_radius" />
<attr name = "layout_shadowColor" />
<attr name="layout_shadowEvaluation" />
<attr name="layout_shadowDx" />
<attr name="layout_shadowDy" />
</declare-styleable>
<! - and EasyLayout list of attributes, but to be named to XXX_Layout format, this tool will prompt the development of custom attributes ->
<DECLARE-styleable name = "EasyConstraintLayout_Layout">
<attr name = "layout_radius" />
<attr name = "layout_shadowColor" />
<attr name = "layout_shadowEvaluation" />
<attr name = "layout_shadowDx" />
<attr name = "layout_shadowDy" />
</ DECLARE-styleable>
</ Resources>
------- -------------- 

Guess you like

Origin www.cnblogs.com/ly570/p/11284698.html