【发布时间】:2011-07-25 01:48:31
【问题描述】:
我正在制作一个需要动态加载布局项的应用程序。 我有一个 XML,其中包含将在舞台上多次添加的元素设计。另外,我有一个保存元素的 RelativeLayout。要将元素添加到 RelativeLayout 我使用这个:
...
View child = View.inflate(context, R.layout.buildinglayout, null);
parrent.addView(child, parrent.getChildCount()); //parrent is the relativeLayout
...
您可能已经猜到,buildinglayout.xml 是元素的布局。一切都正确地添加到舞台上,显然没有问题。问题是该元素要适合舞台,所以我需要有一个围绕RelativeLayout 的ScrollView。唯一的问题是滚动视图没有检测到RelativeLayout的实际宽度和高度。所以...我这样做了:
...
View child = View.inflate(context, R.layout.buildinglayout, null);
parrent.addView(child, parrent.getChildCount()); //parrent is the relativeLayout
Log.v("BuildingView", "w:" + child.getWidth() + " h:" + child.getHeight());
Log.v("ParrentView", "w:" + parrent.getWidth() + " h:" + parrent.getHeight());
...
那些 Log.v 的输出是:
03-29 06:56:43.803: VERBOSE/BuildingView(480): w:0 h:0
03-29 06:56:43.803: VERBOSE/ParrentView(480): w:0 h:752
谁能告诉我该怎么做才能使 buildingview 和 parrent 的宽度和高度都正确?
附:我在模拟器设备上使用 Android 3.0
【问题讨论】:
标签: android