具有两个元素的框架布局

发布于 2024-12-25 03:20:54 字数 1033 浏览 3 评论 0原文

我得到了一个 FrameLayout,它有两个元素,一个 TextView 和一个带有背景颜色的 View。 在 eclips 预览中,它按预期显示,视图覆盖了 Textview。 然而,当我将此布局扩展到另一个布局时,彩色视图就会消失。有什么建议吗?

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" >
    <View
        android:layout_width="wrap_content"
        android:layout_height="10dp" android:background="#000" android:layout_gravity="bottom" android:id="@+id/viewActive"/>
    <TextView
        android:id="@+id/textViewName"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Medium Text"
        android:textAppearance="?android:attr/textAppearanceMedium"/>
</FrameLayout>

这是包含的代码

LayoutInflater inflater = LayoutInflater.from(context);
ViewGroup view2 = (ViewGroup) inflater.inflate(R.layout.frame_layout, null);
anotherViewGroup.addView(view2);

I got a FrameLayout which has two elements, a TextView and a View with a Backgroundcolor.
Whithin eclips previw this shows up as expected, the view overlays the Textview.
Howewer when i am inflating this layout into another the colored view just disapears. any suggestions?

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" >
    <View
        android:layout_width="wrap_content"
        android:layout_height="10dp" android:background="#000" android:layout_gravity="bottom" android:id="@+id/viewActive"/>
    <TextView
        android:id="@+id/textViewName"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Medium Text"
        android:textAppearance="?android:attr/textAppearanceMedium"/>
</FrameLayout>

This is the code for include

LayoutInflater inflater = LayoutInflater.from(context);
ViewGroup view2 = (ViewGroup) inflater.inflate(R.layout.frame_layout, null);
anotherViewGroup.addView(view2);

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

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

发布评论

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

评论(1

挖个坑埋了你 2025-01-01 03:20:54

您的普通视图的宽度设置为“wrap_content”。这意味着视图应该与我的内容一样大,但它没有任何内容,因此宽度实际上为 0,使其不可见。

尝试将宽度设置为硬编码值,例如“10dp”或“match_parent”。那应该可以解决问题。

Your plain view's width is set to "wrap_content". That means the view should be as big as my content but it doesn't have any content so the width is effectively 0, making it invisible.

Try setting the width to a hardcoded value like "10dp" or "match_parent". That should do the trick.

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