0

我目前正在尝试创建一个嵌入在 Scrollview 中的 RelativeLayout(因此可以垂直滚动 RelativeLlayout 的内容)。我的布局文件如下所示:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" >

        <TextView
            android:id="@+id/label_first_day_of_budget_cycle"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_alignParentLeft="true"
            android:layout_alignParentTop="true"
            android:layout_margin="10dp"
            android:text="@string/first_day_of_budget_cycle"
            android:textSize="20sp" />

        <include
            android:id="@+id/settings_divider_one"
            android:layout_alignParentLeft="true"
            android:layout_below="@id/label_first_day_of_budget_cycle"
            layout="@layout/w_divider" />

        <TextView
            android:id="@+id/label_monthly_income"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_alignParentLeft="true"
            android:layout_below="@id/settings_divider_one"
            android:layout_margin="10dp"
            android:text="@string/monthly_income"
            android:textSize="20sp" />

        <include
            android:id="@+id/settings_add_income"
            android:layout_alignParentLeft="true"
            android:layout_below="@id/label_monthly_income"
            layout="@layout/w_add" />

        <include
            android:id="@+id/settings_divider_two"
            android:layout_alignParentLeft="true"
            android:layout_below="@id/settings_add_income"
            layout="@layout/w_divider" />

        <TextView
            android:id="@+id/label_monthly_expenses"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_alignParentLeft="true"
            android:layout_below="@id/settings_divider_two"
            android:layout_margin="10dp"
            android:text="@string/monthly_expenses"
            android:textSize="20sp" />

        <include
            android:id="@+id/settings_add_expenses"
            android:layout_alignParentLeft="true"
            android:layout_below="@id/label_monthly_expenses"
            layout="@layout/w_add" />

        <include
            android:layout_alignParentLeft="true"
            android:layout_below="@id/settings_add_expenses"
            layout="@layout/w_divider" />
    </RelativeLayout>

</ScrollView>

这就是它在我手机上的样子:

在此处输入图像描述

我尝试了我能想到/在网络或 stackoverflow 上找到的所有可能的变体,但到目前为止都没有成功。我不确定我还能尝试什么或我在这里缺少什么。

我尝试改变 RelativeLayout 和 Scrollview 的 layout_width 和 layout_height 值,但没有成功。任何关于我做错了什么的提示将不胜感激。

更新

按照本的建议,我删除了包含,然后布局正确呈现。我提交了一个错误报告点击,因为我认为,其中包括应该与嵌入在 Scrollviews 中的 RelativeLayouts 一起使用。至少我看不出他们不应该这样做的理由。如果我的布局包含另一个阻止包含正常工作的错误,我想/希望我会在票证中得到相应的答复。

4

2 回答 2

1

include据我记得,在带有 ScrollViews 的 xml 中存在某种问题。您可以尝试用实际的 xml 替换包含吗?

于 2013-01-03T21:53:31.790 回答
0

尝试使用LinearLayout带有宽度和高度的 afill_parent而不是RelativeLayout.

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent" android:layout_height="fill_parent" >
    <LinearLayout android:orientation="vertical"
            android:layout_width="fill_parent" android:layout_height="fill_parent" >
          ... your content here

用于RelativeLayout垂直对齐元素是一个坏主意(性能较慢 + 不易阅读)。如果您确实需要相对布局,可以将其添加到 LinearLayout 元素中。确保宽度和高度是fill_parent.

于 2013-01-03T21:57:29.567 回答