2013-01-03 35 views
0

我目前正试图创建一个嵌入ScrollView的RelativeLayout(因此RelativeLlayout的内容可以垂直滚动)。我的布局文件看起来是这样的:Android:滚动视图中的RelativeLayout全部堆积在现场

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

,这是它的外观我的电话:

enter image description here

我想尽一切可能的变化我能想到的/发现在网络上或计算器,迄今为止没有成功。我不知道我还能尝试什么,或者我在这里失去了什么。

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

UPDATE

继Ben的建议,我删除了包括再布局呈现正常。我提交了一个错误报告click因为我的意见是,包括应该与嵌入到Scrollviews中的RelativeLayouts一起工作。至少我没有看到他们不应该这样做的理由。如果我的布局包含另一个错误,以防止包括工作正常,我想/我希望我会在票据中相应地回复 。

回答

1

从我记得,在与ScrollViews xml include有一些问题。你可以尝试用实际的xml代替包含吗?

+0

我尝试了你的建议,并解决了这个问题:哦!但从技术上讲,这意味着,他们的包含功能无法正常工作?你知道是否有任何机会有相关的错误报告?我真的不想复制粘贴所有这些包括-_-,但无论哪种方式解决神秘的:) - 非常感谢! – AgentKnopf

+0

不幸的是,我不能告诉你任何关于这个问题的更多信息,但是如果你发现了这个问题的解决方案,请告诉我;) – ben

+0

确定的事情:) - 我只希望有人足够仁慈地检查我提交的xD错误报告 – AgentKnopf

0

尝试使用宽度和高度为LinearLayout而不是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

+0

感谢您的回答。我需要一个相对布局(上面的布局不是最终版本)。我可能会切换到LinearLayout,但我想知道,如果它根本不可能将一个RelativeLayout添加到滚动视图?是否必须将RelativeLayout嵌入LinearLayout中,然后嵌入到Scrollview中?这似乎是非常浪费:(? – AgentKnopf

+0

你是对的,但我没有一个答案,没有花一些时间尝试。另一方面,我花了很多时间在Android的性能和RelativeLayout是很难计算只是因为它的灵活性,因为你想要线性滚动,它应该适合线性布局,你仍然可以使用一些较小的相对布局,但是当然如果你的布局非常复杂并且使用相对布局会减少布局深度,它是有道理的 – yigit

+0

感谢您的洞察力,布局不会太复杂,但没有RelativeLayout我会被要求嵌套LinearLayouts等达到相同的效果。令我厌烦的是,这些包括以及为什么它们不能在嵌入到ScrollView中的RelativeLayout中工作:S – AgentKnopf