“工作区” Google“iosched”上的子视图未填充高度应用程序

发布于 2024-11-13 09:46:54 字数 1861 浏览 2 评论 0原文

我正在使用 Google I/O 2011 上的 iosched 应用程序。查看 ScheduleFragment ,我正在 工作区 子项,用于来回翻页。然而,我很难让我的孩子的观点来填补父母的意见。我添加了几种背景颜色和一些填充来显示所有内容的布局位置。这是我的测试...

我向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);

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

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

您将看到红色工作区填充了可用的父空间,但绿色 LinearLayout 没有填充。我缺少什么?

I'm playing around with the iosched app from Google I/O 2011. Looking at the ScheduleFragment, I'm testing a different view on the Workspace children for flinging the pages back and forth. However, I'm having trouble getting my child views to fill the parent. I added several background colors and some padding to show where everything is laying out. Here's my test...

I added a red background color to the "Workspace" item in fragment_schedule.xml like this...

android:background="#cc0000"

Then, instead of using blocks_content.xml for the child view, I created my own pending_content.xml that is simply a green-background LinearLayout (with fill_parent for height) and a blue-background TextView (also with fill_parent for height) with a simple text line.

<?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 add my view just like the I/O app has "days"...

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);

And here's what I see when I view it on the device:

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

You'll see that the red Workspace fills the available parent space, but the green LinearLayout does not. What am I missing?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

孤君无依 2024-11-20 09:46:54

问题是,在您的膨胀步骤中:

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

您丢失了 XML 中定义的 LayoutParams ,并且您的视图实际上最终以默认布局参数结束。

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

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

这将允许布局膨胀器构造一组适当的LayoutParams您的子视图来自已解析的 XML 属性。

The problem is that during your inflation step:

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

You lose the LayoutParams defined in your XML, and your view actually ends up with default layout parameters.

What you need to do is provide a root and simply not attach the inflated layout to the root during inflation:

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

This will allow the layout inflater to construct an appropriate set of LayoutParams for your child view from the parsed XML attributes.

情绪失控 2024-11-20 09:46:54

我想出了一个解决办法。我开始调试 Workspace.java 中的 onLayout 。在 child.layout 函数调用中,我将 child.getMeasuredHeight() 更改为 this.getMeasuredHeight() 以使用工作区的高度。

对于比工作区高度短的页面以及比工作区高度大的子页面(长 ListView)的情况,似乎工作得很好。

I figured out a solution. I started debugging the onLayout in Workspace.java. In the child.layout function call, I changed child.getMeasuredHeight() to this.getMeasuredHeight() to use the height of the workspace instead.

Seems to work fine for the case of a page that is shorter than the workspace height as well as a child that is bigger (a long ListView) that is larger than the height of the workspace.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文