android和view相关的东西
2013-05-22 21:49
183 查看
findViewById(R.id.xxxx),把xml里面的控件根据id绑定到类成员变量,适用于普通控件和布局
LayoutInflater,用于把布局xml里面的东西实例化(会重新实例化,和findViewById不同),sample代码如下
LayoutInflater inflator = getLayoutInflater();
//注意,这里参数是layout,不是id
RelativeLayout layout = (RelativeLayout)inflator.inflate(R.layout.activity_main, null);
TextView aTextView = new TextView(this);
aTextView.setWidth(100);
aTextView.setHeight(100);
aTextView.setText("asdasdasdasd");
layout.addView(aTextView);
//采用LayoutInflater的需要重新设置布局才有效果。
setContentView(layout);
附三种使用LayoutInflater的方法
LayoutInflater inflater = LayoutInflater.from(this);
View layout = inflater.inflate(R.layout.main, null);
LayoutInflater inflater = getLayoutInflater();
View layout = inflater.inflate(R.layout.main, null);
LayoutInflater inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(R.layout.main, null);
LayoutInflater,用于把布局xml里面的东西实例化(会重新实例化,和findViewById不同),sample代码如下
LayoutInflater inflator = getLayoutInflater();
//注意,这里参数是layout,不是id
RelativeLayout layout = (RelativeLayout)inflator.inflate(R.layout.activity_main, null);
TextView aTextView = new TextView(this);
aTextView.setWidth(100);
aTextView.setHeight(100);
aTextView.setText("asdasdasdasd");
layout.addView(aTextView);
//采用LayoutInflater的需要重新设置布局才有效果。
setContentView(layout);
附三种使用LayoutInflater的方法
LayoutInflater inflater = LayoutInflater.from(this);
View layout = inflater.inflate(R.layout.main, null);
LayoutInflater inflater = getLayoutInflater();
View layout = inflater.inflate(R.layout.main, null);
LayoutInflater inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(R.layout.main, null);
相关文章推荐
- Android中View绘制流程以及invalidate()、requestLayout()等相关方法分析
- Android View XML属性 相关方法 及 说明
- Android中与ViewRoot相关的一些概念
- Android中View绘制流程以及invalidate()等相关方法分析
- android 自定义ImageView -图片显示相关1
- Android中View绘制流程以及invalidate()等相关方法分析
- android内部培训视频_第三节(3)_常用控件(ViewPager、日期时间相关、ListView)
- Android 自定义View触摸相关工具类详解
- 【Android View相关】View的绘制机制
- android中与Adapter相关的控件----ViewFlipper
- android RecyclerView相关
- android TextView 相关的知识点 汇总
- android view 相关方法 layout draw 布局 重绘
- Android中View绘制流程以及invalidate()等相关方法分析
- Android中View绘制流程以及invalidate()等相关方法分析
- Android自定义View研究(六)--View中的原点坐标相关问题
- Android View绘制流程以及invalidate()等相关方法分析
- Android开发之Android4.4的状态栏变色相关的东西
- 【android_温故知新】View 类的 XML 属性及相关方法说明
- Android中View绘制流程以及invalidate()等相关方法分析