android开发 BaseAdapter中getView()里的ViewGroup是什么意思
publicViewgetView(intposition,ViewconverView,ViewGroupparent){}中的ViewGroupparent是什么为什...
public View getView(int position,View converView,ViewGroup parent){}
中的ViewGroup parent是什么
为什么每次使用是定义成null也能照常用? 展开
中的ViewGroup parent是什么
为什么每次使用是定义成null也能照常用? 展开
展开全部
应该去看下源码,parent是item的view的父视图,调整item宽高用的,你自定义一个viewGroup的时候除了通常要重写onLayout onMeasure等方法,计算子view的宽高,如果有了这个parent参数,并且后面的attachToRoot值为否,则会从parent中提取layout_width和layout_height组成LayoutParams,设给convertView。
源码:
ViewGroup.LayoutParams params = null;
if (root != null) {
if (DEBUG) {
System.out.println("Creating params from root: " +
root);
}
// Create layout params that match root, if supplied
params = root.generateLayoutParams(attrs);
if (!attachToRoot) {
// Set the layout params for temp if we are not
// attaching. (If we are, we use addView, below)
temp.setLayoutParams(params);
}
}
if (root != null && attachToRoot) {
root.addView(temp, params);
}
// Decide whether to return the root that was passed in or the
// top view found in xml.
if (root == null || !attachToRoot) {
result = temp;
}
源码:
ViewGroup.LayoutParams params = null;
if (root != null) {
if (DEBUG) {
System.out.println("Creating params from root: " +
root);
}
// Create layout params that match root, if supplied
params = root.generateLayoutParams(attrs);
if (!attachToRoot) {
// Set the layout params for temp if we are not
// attaching. (If we are, we use addView, below)
temp.setLayoutParams(params);
}
}
if (root != null && attachToRoot) {
root.addView(temp, params);
}
// Decide whether to return the root that was passed in or the
// top view found in xml.
if (root == null || !attachToRoot) {
result = temp;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询