android - "Workspace" subview 未在 Google "iosched"应用程序上填充高度

标签 android workspace fill-parent

我正在玩弄 iosched来自 Google I/O 2011 的应用程序。查看 ScheduleFragment,我在 Workspace 上测试不同的 View children 来回翻动书页。但是,我无法让我的 child 的观点来填充 parent 。我添加了几种背景颜色和一些填充以显示所有内容的布局。这是我的测试...

我像这样在 fragment_schedule.xml 中的“工作区”项中添加了红色背景色...

android:background="#cc0000"

然后,我没有为 subview 使用 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>

我添加我的 View 就像 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);

这是我在设备上查看时看到的内容:

http://www.milescrew.com/images/workspace.png

您会看到红色的 Workspace 填充了可用的父空间,但绿色的 LinearLayout 没有。我错过了什么?

最佳答案

问题是在你的通货膨胀步骤中:

view.rootView = (ViewGroup) inflater.inflate(R.layout.pending_content, null);

您丢失了在 XML 中定义的 LayoutParams,您的 View 实际上以默认布局参数结束。

您需要做的是提供一个 root 并且在充气期间不要将充气布局附加到根:

view.rootView = (ViewGroup) inflater.inflate(R.layout.pending_content, mWorkspace, false);

这将允许布局 inflater 从解析的 XML 属性为您的 subview 构造一组适当的 LayoutParams

关于android - "Workspace" subview 未在 Google "iosched"应用程序上填充高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6229594/

相关文章:

eclipse - 为什么我的 Eclipse 在启动时不要求工作区?

Android 自定义布局管理器 - 子布局

java - 需要帮助构建 Android 版本的 javax.sampled。音频输入流

android - 从 Android Studio 停止 Android adb

java - 单击可扩展 ListView 中的子项时如何在另一个 Activity 中打开 ListView

eclipse - 在 Eclipse 中创建一个新工作区

eclipse - 在工作空间外使用 eclipse 项目(多用户)

android - TextView 高度不匹配_parent/fill_parent

android - 关于Android中DP的问题

android - 不使用 WRITE_EXTERNAL_STORAGE 共享图像?