Android 怎么在一个线性布局中动态添加一个已经存在的布局

Android 怎么在一个线性布局中动态添加一个已经存在的布局,第1张

在Android的layout样式定义中,可以使用xml文件方便的实现,有时候为了模块的复用,使用include标签可以达到此目的。

<Linearlayout

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:layout_below="@id/top" >

<include layout="@layout/otherlayout">

</Linearlayout

private ViewGroup group\x0d\x0aprivate ViewGroup main\x0d\x0amain = (ViewGroup) inflater.inflate(R.layout.main, null)//这里的R。latout.main就是当前布局\x0d\x0agroup = (ViewGroup) main.findViewById(R.id.viewGroup)\x0d\x0a group.addView(imageViews[i])//这样就把一个imageview(你可添加一个任意复杂的View,这个View实例化的时候指向你所谓的其他布局文件)加入当前布局中的某个ViewGroup里了,你布局时可定义一个LinearLayout id 设为(R.id.viewGroup),oratation设为垂直,放到下面就是了。

在文件管理器里直接copy进去然后项目右键刷新(refresh),或者项目layout右键new->xml File,然后拷贝你的代码,或者直接鼠标拖动一个xml文件直接拉到eclipse layout文件夹下~


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/bake/11710233.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-05-18
下一篇2023-05-18

发表评论

登录后才能评论

评论列表(0条)

    保存