public class MyLayout extends RelativeLayout{
private Context context;
public MyLayout(Context context){
super(context);
this.context = context;
RelativeLayout main = new RelativeLayout(context);
RelativeLayout.LayoutParams lp_main_view = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.FILL_PARENT, RelativeLayout.LayoutParams.FILL_PARENT);
main.setBackgroundColor(Color.parseColor("#FF00FF"));
main.setLayoutParams(lp_main_view);
/*GifView gif_view = new GifView(context);
gif_view.setGifImage(R.drawable.gif_test);
RelativeLayout.LayoutParams lp_gif_view = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
lp_gif_view.addRule(RelativeLayout.ALIGN_PARENT_TOP);
lp_gif_view.addRule(RelativeLayout.CENTER_HORIZONTAL, RelativeLayout.TRUE);
// btn1 位于父 View 的顶部,在父 View 中水平居中
main.addView(gif_view, lp_gif_view);*/
TextView t = new TextView(context);
t.setText("怎么就不显示呢");
RelativeLayout.LayoutParams lp_t_view = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
lp_t_view.addRule(RelativeLayout.ALIGN_PARENT_TOP);
lp_t_view.addRule(RelativeLayout.CENTER_HORIZONTAL, RelativeLayout.TRUE);
main.addView(t, lp_t_view);
}
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
super.onLayout(changed, l, t, r, b);
}
/**
* 测量尺寸时的回调方法
*/
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
}
以上是我自定义的view
我在activity里
`MyLayout myLayout = new MyLayout(this);
setContentView(myLayout);`
以这种方式加载 为什么显示不出来
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。