返回信息流public View getView(int position, View convertView, ViewGroup parent)中,ViewGroup parent这个参数的parent指的是什么?
这是一条镜像帖。来源:北邮人论坛 / java / #37302同步于 2014/12/23
该镜像源已超过 30 天没有更新,可能在源站已被删除。
Java机器人发帖
listview的baseadapter中getview函数的parent参数是做什么用的
WenDing
2014/12/23镜像同步6 回复
订阅后,新回复会通过你的通知中心匿名送达。
6 条回复
convertView = inflater.inflate(R.layout.list_item, parent, false);
parent的意义在于,如果你传入了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;
}
【 在 WenDing (维护稳定大局,共建和谐校园) 的大作中提到: 】
: public View getView(int position, View convertView, ViewGroup parent)中,ViewGroup parent这个参数的parent指的是什么?
这个我知道,不过在getview里面用到的inflate函数中的parent参数是指的哪个视图?
【 在 dss886 的大作中提到: 】
: convertView = inflater.inflate(R.layout.list_item, parent, false);
: parent的意义在于,如果你传入了parent并且后面的attachToRoot值为否,则会从parent中提取layout_width和layout_height组成LayoutParams,设给convertView。
: 源码:
: ...................
还有一个问题,就是说public View inflate(int resource,View Grouproot,boolean attachToRoot)
中的View Grouproop是指哪一个视图?是指的resource的根视图么?
【 在 dss886 的大作中提到: 】
: convertView = inflater.inflate(R.layout.list_item, parent, false);
: parent的意义在于,如果你传入了parent并且后面的attachToRoot值为否,则会从parent中提取layout_width和layout_height组成LayoutParams,设给convertView。
: 源码:
: ...................
listview每一项的根视图吧,就是你载入的xml视图的直接父视图
http://developer.android.com/reference/android/widget/Adapter.html#getView(int, android.view.View, android.view.ViewGroup)
parent The parent that this view will eventually be attached to
【 在 WenDing (维护稳定大局,共建和谐校园) 的大作中提到: 】
: 这个我知道,不过在getview里面用到的inflate函数中的parent参数是指的哪个视图?
: [upload=1][/upload]
哦哦,谢谢大牛!
【 在 dss886 的大作中提到: 】
: listview每一项的根视图吧,就是你载入的xml视图的直接父视图
: http://developer.android.com/reference/android/widget/Adapter.html#getView(int, android.view.View, android.view.ViewGroup)
: parent The parent that this view will eventually be attached to
: ...................