1.init() {
post(...) {
setBitmap(...); // 自定义Imageview
}
}
2.组合控件
public class MyLinearViewGroup extends LinearLayout {
init() {
...
getContext();
LayoutParams params = new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT);
params.addRule(ALIGN_PARENT_BOTTOM);
button.setLayoutParams(params);
addView(button); // 每个ViewGroup类的控件都有该方法,动态添加子控件或子布局
}
}
View.setTag("...");
3.自定义属性
res/values ——> attrs
<resources>
<declare-styleable name="MyLinearViewGroup">
<attr name="myText" format="String"/>
<attr name="myColor" format="color"/>
</declare-styleable>
</resources>
<RelativeLayout
...
appNs
...>
<com.xxx.MyLinearViewGroup
...
app:myText="..."
app:myColor="#f00"/>
</RelativeLayout>
init(Context context, AttributeSet attrs) {
TypedArray array = context.obtainStyledAttributes(attrs, R.styleable.MyLinearViewGroup);
String text = array.getString(R.styleable.MyLinearViewGroup_myText);
}