0
RelativeLayout item = (RelativeLayout)findViewById(R.id.catalogParent);

View child = getLayoutInflater().inflate(R.layout.detailedcatalog, null);

RelativeLayout.LayoutParams layoutParams = new
RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT);

layoutParams.addRule(RelativeLayout.BELOW,view.getId());

item.addView(child, layoutParams);

上面是在列表视图元素下方放置布局的代码。view.getId() 函数总是返回 -1。相对布局在运行时以编程方式膨胀。

lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {

@Override
public void onItemClick(AdapterView<?> arg0, View view,
int position, long arg3) {
...}}

视图对象是从 onItemClick 函数中获得的。你能帮我解决这个问题吗?提前致谢。

4

1 回答 1

0

所以我使用了 view.getLocationInWindow(location),其中 location 是一个大小为 2 的 int 数组,它给出了 listview 元素在屏幕上的位置,然后我使用获得的坐标将相对布局相应地放置在屏幕上从位置。

于 2012-06-28T16:04:16.277 回答