Framelayout有两个元素

时间:2012-01-05 06:20:22

标签: android layout android-framelayout

我有一个FrameLayout,它有两个元素,一个TextView和一个带Backgroundcolor的视图。 虽然预览会显示正常情况,但视图会覆盖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);

1 个答案:

答案 0 :(得分:0)

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

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

相关问题