2014-10-18 85 views
0

我需要自定义按钮的每个实例使用FrameLayout作为其布局。我如何从我的自定义Button类做到这一点,以避免必须将每个定义的CustomButton定义在FrameLayout中?Android +自定义按钮内的充气布局

public CustomButton(Context context) { 
    super(context); 
    init(context); 
} 

public CustomButton(Context context, AttributeSet attrs) { 
    super(context, attrs); 
    init(context); 
} 

public CustomButton(Context context, AttributeSet attrs, int defStyle) { 
    super(context, attrs, defStyle); 
    init(context); 
} 

private void init(Context context) { 
//this doesn't work... 
    FrameLayout layout = new FrameLayout(context); 
    inflate(context, R.layout.frame_layout, null);   
} 

回答

1

只是把你的FrameLayout arount您的自定义按钮,在frame_layout,后来在其他XML,你可以把它作为这种观点将是因为它是在frame_layout

+0

有道理。虽然看到它以编程方式完成会很高兴。 – worked 2014-10-19 00:27:00