0

我得到了一个 FrameLayout,它有两个元素,一个 TextView 和一个带有 Backgroundcolor 的 View。Whithin eclips previw 这按预期显示,视图覆盖了 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);
4

1 回答 1

0

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

尝试将宽度设置为硬编码值,例如“10dp”或“match_parent”。这应该够了吧。

于 2012-01-05T06:41:06.073 回答