LayoutInflater 和 ExpandableListView

发布于 2024-11-17 09:14:56 字数 597 浏览 7 评论 0原文

我对 Android 还很陌生,但我已经做到了!

我创建了一个与 android 开发人员上的 api 示例代码几乎相同的 ExpandableListView 网站。 ExpandableList 的效果非常好。

我尝试通过 xml 和 SimpleExpandableAdaptor 创建自定义布局,但做了噩梦。这让我明白了这一点:

我已经阅读了很多有关 LayoutInflaters 以及它们如何与 XML 文件配合使用的内容。但是,我想创建两个单独的 ImageButton,并将它们放置在 groupExpanded 指示器(在 TextView 组中)旁边,而不引用 xml。我认为我不能使用 xml 来执行此操作,因为 API 提供的代码不依赖于 xml(其创建的运行时)。

LayoutInflater 在这种情况下可以工作吗(没有 xml)?有人建议我可以在哪里寻找干净的解决方案吗?

提前致谢。

I am still fairly new to android, but I am getting there!

I have created an ExpandableListView almost identical to the api sample code on the android developers website. The ExpandableList works wonderfully.

I tried creating custom layouts through xml and a SimpleExpandableAdaptor and had nightmares. Which brings me to the point:

I have been reading a lot about LayoutInflaters and how well they work with XML files. However, I would like to create two seperate ImageButtons and place them next to the groupExpanded indicator (in the group TextView) with out referencing xml. I don't think I can use xml to do this simply because the code supplied by API doesn't rely on xml, its created runtime.

Can LayoutInflater work in this situation (no xml)? Does anyone have suggestions where I might look for a clean solution?

Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

z祗昰~ 2024-11-24 09:14:56

您可以同时执行这两种操作,即使用 LayoutInflater 扩充 xml 布局,或者使用 Android 对象模型创建 View 元素。我建议使用 xml 文件,因为您可以轻松地将布局更改为稍后的点,而无需触摸代码。

看看这篇博客帖子,它展示了如何为 ExpandableListView 扩展适配器中的布局。

You can do both, either inflate a xml layout using a LayoutInflater or creating the View elements using the Android object model. I would suggest using xml files as you can easily change the layout to a later point without touching the code.

Have a look at this blog post it shows how to inflate layouts in an adapter for a ExpandableListView.

旧夏天 2024-11-24 09:14:56

我相信 LayoutInflater 用于将 XML 布局加载到 View 对象中的明确目的。或者,您可以通过构造RelativeLayout/LinearLayout等来创建自己的视图,并以编程方式向其中添加ImageButtons

LinearLayout layout = new LinearLayout(context);
layout.setOrientation(LinearLayout.HORIZONTAL);
layout.addView(imageButton1);
layout.addView(imageButton2);

I believe LayoutInflater is used for the express purpose of loading an XML layout into a View object. Alternately, you can create your own view by constructing RelativeLayout/LinearLayout etc. and programmatically adding your ImageButtons to it

LinearLayout layout = new LinearLayout(context);
layout.setOrientation(LinearLayout.HORIZONTAL);
layout.addView(imageButton1);
layout.addView(imageButton2);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文