如何在android中使用框架布局

发布于 2024-12-15 11:50:17 字数 491 浏览 5 评论 0原文

我必须创建一个 android 布局,顶部有一个 textview,在该 textview 下有一个 imageview 和一个 imagebutton > 在 imageview 下。

当触摸 imagebutton 时,textviewimageview 必须变得不可见,并且自定义视图必须在 textview< 的位置变得可见。 /code> 和 imageview 是。

如果我使用线性布局,我必须使用 margintop 白色负值,但我认为这不是很有用,因为在不同的屏幕尺寸上它会显示得非常糟糕。我想我必须使用 framelayout 但我不知道该怎么做,谁能解释一下它是如何工作的吗?

非常感谢你!

i have to create an android layout which has a textview on the top, an imageview under that textview and a imagebutton under imageview.

When imagebutton is touched, the textview and imageview have to become invisible and a custom view must become visibile in the place where textview and imageview was.

If i use linearlayout, i have to use margintop whit negative values, but i think is not very useful cause on different screen size it will shown very bad. I think i have to use framelayout but i don't know how to do, can anyone explain me well how it work pls?

thanks you very much!

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

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

发布评论

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

评论(2

东走西顾 2024-12-22 11:50:17

为什么要采用 FrameLayout?在您的 LinearLayout 中执行此操作。当触摸 imageButton 时,将文本和 imageView 设置为:

imageView.setVisibility(View.GONE)

并将您的自定义视图设置为 View.Visible。

我猜你的边距是负数,因为你尝试了像 View.Invisible 这样的东西。
您可以参考docs,查看,每个州做什么。

Why you want to take an FrameLayout? do it inside your LinearLayout. When imageButton is touched set text and imageView like this :

imageView.setVisibility(View.GONE)

and your customView to View.Visible.

I guess you came to negative margins, because you tried something like View.Invisible.
You can refer to the docs, to see, what each state does.

走野 2024-12-22 11:50:17

比 LinearLayout 更好的方法是使用relativelayout。为覆盖组件提供相同的属性,并且不要设置相对属性,例如layoutabove 或layoutbelow。

A better way than LinearLayout is using RelativeLayout. Give the same attributes to the overlaying components and do not set the relative attributes like layoutabove or layoutbelow.

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