【发布时间】:2011-06-08 16:41:26
【问题描述】:
我正在使用来自 Google I/O 2011 的 iosched 应用程序。查看 ScheduleFragment,我正在测试 Workspace 子级的不同视图,用于来回翻转页面。但是,我无法让我的孩子的意见填补父母。我添加了几种背景颜色和一些填充以显示所有内容的布局。这是我的测试...
我像这样在 fragment_schedule.xml 中的“工作区”项中添加了红色背景色...
android:background="#cc0000"
然后,我没有使用 blocks_content.xml 作为子视图,而是创建了自己的 pending_content.xml,它只是一个绿色背景的 LinearLayout(高度为 fill_parent)和一个蓝色背景的 TextView(高度也为 fill_parent)用一个简单的文本行。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:id="@+id/container"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#00cc00"
android:padding="5dip"
xmlns:android="http://schemas.android.com/apk/res/android">
<TextView
android:id="@+id/text_view"
android:background="#0000cc"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="Pending Content"
android:textColor="#ffffff"
/>
</LinearLayout>
我添加我的视图,就像 I/O 应用程序有“天”一样...
ViewGroup root = (ViewGroup) inflater.inflate(R.layout.fragment_schedule, null);
mWorkspace = (Workspace) root.findViewById(R.id.workspace);
ShootView view = new ShootView();
view.index = mViews.size();
view.rootView = (ViewGroup) inflater.inflate(R.layout.pending_content, null);
view.label = "Pending";
mWorkspace.addView(view.rootView);
mViews.add(view);
这是我在设备上查看时看到的内容:
您会看到红色的 Workspace 填充了可用的父空间,但绿色的 LinearLayout 没有。我错过了什么?
【问题讨论】:
-
工作区本身是否有
layout_height="fill_parent"? -
是的,除了添加背景颜色之外,我没有更改该 XML。您可以看出 Workspace 正在填充父级,因为红色正在填充背景。除了添加背景色外,和... code.google.com/p/iosched/source/browse/android/res/layout/…
-
如果你只是以编程方式给孩子一个新的 LayoutParams 会发生什么?
-
我也可以试试。目前我正在使用我在您的回答中提到的方法(将 child.getMeasuredHeight 替换为 this.getMeasuredHeight)。
标签: android workspace fill-parent