带有 inflate xml 和子节点的自定义 LinearLayout
我有一个自定义导航类,其中有常见的视图,因此我想将它们放入一个布局中,该布局将由自定义类膨胀,并在主布局上放置一些导航项。
目前,当我扩展线性布局时,xml中的视图替换了膨胀视图中的所有视图(我将此代码放在构造函数上)
((Activity) context).getLayoutInflater().inflate(R.layout.navigation_group, this ,true);
有没有一种方法可以让我膨胀布局并获取xml实现的子级并放置是在一个视图上吗?就像
的布局
<com.mycompany.NavigationGroup> <Text android:text="title" ... /> <Button android:text="collapse" ... /> <LinearLayout android:id="@+id/navigationItemHolder ... /> <Text android:text="descriptions" ... /> </com.mycompany.NavigationGroup>
在主布局中使用
<com.mycompany.NavigationGroup> <Button android:text="menu 1" /> <Button android:text="menu 2" /> </com.mycompany.NavigationGroup>
一样,我的问题是如何将菜单 1 和 1 放在菜单 2 中?菜单 2 位于 navigationItemHolder 内?谢谢
I have a custom navigation class where there are common views therefore i was thinking to put them into one layout which is to be inflated by the custom class and on the main layout ill put some navigation item on it.
Currently when i extends linearlayout, the views in the xml replaces all the views in the inflated view (i put this code on constructor)
((Activity) context).getLayoutInflater().inflate(R.layout.navigation_group, this ,true);
Is there a way where i could inflate a layout and get the child of the xml implementation and put it on one view? like
layout to be inflated
<com.mycompany.NavigationGroup> <Text android:text="title" ... /> <Button android:text="collapse" ... /> <LinearLayout android:id="@+id/navigationItemHolder ... /> <Text android:text="descriptions" ... /> </com.mycompany.NavigationGroup>
used in main layout
<com.mycompany.NavigationGroup> <Button android:text="menu 1" /> <Button android:text="menu 2" /> </com.mycompany.NavigationGroup>
My question is how could i put menu 1 & menu 2 inside navigationItemHolder? Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以在膨胀布局后以编程方式执行此操作。我相信你可以做这样的事情:
You can do this programmatically after you inflate your layout. I believe you can do something like this: