具有两个元素的框架布局
我得到了一个 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的普通视图的宽度设置为“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.