我正在处理的应用程序需要显示配置文件的HorizontalScrollView的动态布局。配置文件只是一个带有图片和文本的RelativeLayout。由于我从数据文件中获取数据,因此我需要为每个配置文件创建一个相对布局。起初,我在for循环中以编程方式创建了每个RelativeLayout,然后将其添加到父视图。这可行,但我不想这样做。我想根据设备的屏幕尺寸使用不同的布局文件等。Android:是否可以制作视图的副本?
然后我想。那么,如果我有一个只有一个配置文件的布局呢?我的代码可以通过findViewById()
获得一个配置文件,然后根据它创建新的配置文件!换句话说:
// get the layout
profileLayout = (LinearLayout) findViewById(R.id.profileLayout);
// get the first profile in the layout
originalProfile = (RelativeLayout) findViewById(R.id.profile1);
// make copy of profile
temporaryProfile = originalProfile;
// make changes to the this profile and add it back
profileLayout.addView(temporaryProfile);
当然,这也不行,因为这是Java和temporaryProfile现在是originalProfile参考。那么是否有任何方法可以制作此RelativeLayout的副本?我知道LayoutInflater,但我仍然不明白它是如何工作的。还有Object.clone()
。
感谢您的回应! – 2012-02-03 17:49:19