在布局中使用布局?

发布于 2024-12-27 18:57:57 字数 84 浏览 1 评论 0原文

通过按按钮更改布局内的内容的最佳方法是什么? 我想要 6 个按钮,每次推送都有不同的内容。

我无法使用选项卡布局,因为我已经使用过它了..

Which is the best way to change the content inside a layout by pressing buttons?
I want 6 buttons and different content for each push.

I cannot use tab layout because i already used it so..

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

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

发布评论

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

评论(3

慵挽 2025-01-03 18:57:57

我建议使用 API 演示中设置的 gridview。您可以将其作为新项目从 Android SDK 导入。

它的工作方式类似于“所有应用程序”列表。但是,您可以更改按钮/图标/文本的布局方式。

I would suggest using the gridview that is set up in API Demos. You can import it in as a new project from the Android SDK.

It works effectively like the list of 'All Apps'. However you can change the way it lays out the buttons/icons/text.

墨小墨 2025-01-03 18:57:57

在我正在开发的应用程序中,我有一个消息类型列表作为按钮。单击按钮可将显示更改为用于撰写所选消息的布局。为此,我为要更改的区域设置了 FrameLayout。我将此视图称为“compose_content”。当我想要更改内容时,我运行以下代码:

compose_content.removeAllViews();
LayoutInflater.from(activity).inflate(R.layout.new_content,compose_content, true);

这会将 FrameLayout 内容更改为指定布局中的内容。

In an app I'm working on, I have a list of message types as buttons. Clicking a button changes the display to a layout for composing the selected message. To do this, I have a FrameLayout for the area I want to change. I reference this view as 'compose_content'. When I want to change the content, I run the following code:

compose_content.removeAllViews();
LayoutInflater.from(activity).inflate(R.layout.new_content,compose_content, true);

This will change the FrameLayout content to the content from the specified layout.

一念一轮回 2025-01-03 18:57:57

一种解决方案是将所有 6 个视图放入膨胀的 xml 中,并根据按下的按钮设置该特定视图的可见性,其余视图消失

One solution can be to have all the 6 views inside your inflated xml and depending on the button pressed set the visibility of that particular view visible and the rest gone

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