2015-10-15 97 views
-3

对于我的应用我有有Android的 - 滚动查看

<Linear Layout> 
    <RelativeLayout> 
    <RelativeLayout> 
    <RelativeLayout> 
    <RelativeLayout> 
    <RelativeLayout> 
    <RelativeLayout> 
    <RelativeLayout> 
    <RelativeLayout> 

在这些相对布局的布局是页面的内容的屏幕,但在其中的一个有以下

<RelativeLayout> 
    <LinearLayout> 
    <LinearLayout> 
    <LinearLayout> 
    <LinearLayout> 

我希望这个内容是可滚动的,但应用程序崩溃,说明可滚动视图只能有一个子项目,反正有这个吗?根据要求

编辑XML

<RelativeLayout 
    android:layout_width="fill_parent" 
    android:layout_height="0dp" 
    android:layout_weight="2.27" 
    > 



    <LinearLayout 
     android:orientation="horizontal" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:id="@+id/linearLayout" 
     android:layout_above="@+id/linearLayout2" 
     android:layout_alignParentStart="true"> 

     <Spinner 
      android:layout_width="0dp" 
      android:layout_height="25dp" 
      android:id="@+id/Combo_FlavChoice1" 
      android:layout_weight="1" 
      android:spinnerMode="dropdown" 
      android:entries="@array/VGPG_combo" 
      /> 

     <Spinner 
      android:layout_width="0dp" 
      android:layout_height="25dp" 
      android:id="@+id/Combo_InvChoice1" 
      android:layout_weight="2" 
      android:spinnerMode="dialog" /> 

     <EditText 
      android:layout_width="0dp" 
      android:layout_height="30dp" 
      android:inputType="numberDecimal" 
      android:ems="10" 
      android:id="@+id/Text_Perc1" 
      android:layout_weight="1" 
      android:textSize="8sp" /> 
    </LinearLayout> 

    <LinearLayout 
     android:orientation="horizontal" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:id="@+id/linearLayout2" 
     android:layout_above="@+id/linearLayout3" 
     android:layout_alignParentStart="true"> 

     <Spinner 
      android:layout_width="0dp" 
      android:layout_height="25dp" 
      android:id="@+id/Combo_FlavChoice2" 
      android:layout_weight="1" 
      android:spinnerMode="dropdown" 
      android:entries="@array/VGPG_combo" /> 

     <Spinner 
      android:layout_width="0dp" 
      android:layout_height="25dp" 
      android:id="@+id/Combo_InvChoice2" 
      android:layout_weight="2" 
      android:spinnerMode="dialog" /> 

     <EditText 
      android:layout_width="0dp" 
      android:layout_height="30dp" 
      android:inputType="numberDecimal" 
      android:ems="10" 
      android:id="@+id/Text_Perc2" 
      android:layout_weight="1" 
      android:textSize="8sp" /> 
    </LinearLayout> 

    <LinearLayout 
     android:orientation="horizontal" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:id="@+id/linearLayout3" 
     android:layout_above="@+id/linearLayout4" 
     android:layout_alignParentStart="true"> 

     <Spinner 
      android:layout_width="0dp" 
      android:layout_height="25dp" 
      android:id="@+id/Combo_FlavChoice3" 
      android:layout_weight="1" 
      android:spinnerMode="dropdown" 
      android:entries="@array/VGPG_combo" /> 

     <Spinner 
      android:layout_width="0dp" 
      android:layout_height="25dp" 
      android:id="@+id/Combo_InvChoice3" 
      android:layout_weight="2" 
      android:spinnerMode="dialog" /> 

     <EditText 
      android:layout_width="0dp" 
      android:layout_height="30dp" 
      android:inputType="numberDecimal" 
      android:ems="10" 
      android:id="@+id/Text_Perc3" 
      android:layout_weight="1" 
      android:textSize="8sp" /> 
    </LinearLayout> 

编辑 - 这是视图看起来应该像

Original

现在:

Now

+0

你能分享你的xml吗? –

+0

ScrollView在哪里? – FlanschiFox

+0

将它删除,因为它导致错误! – Sjharrison

回答

0

从文档(http://developer.android.com/reference/android/widget/ScrollView.html):

ScrollView是一个FrameLayout,这意味着你应该放置一个包含整个内容的子项来滚动;这个孩子本身可能是一个具有复杂对象层次结构的布局管理器。一个经常使用的孩子是一个垂直方向的LinearLayout,呈现一个顶级项目的垂直数组,用户可以滚动浏览。

你只需要将你的外部RelativeLayout包装在一个ScrollView中。另外,它看起来像在RelativeLayout中将3个LinearLayouts放在另一个的顶部,将它们放在LinearLayout中并使该wrap_content的高度更好?

0

添加一个LinearLayout到你的ScrollView并用你的RelativeLayouts填充那个。类似这样的:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <ScrollView 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:id="@+id/scrollView" > 

      <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content"> 

      add your stuff here 

      </LinearLayout> 
    </ScrollView> 
</FrameLayout> 
+0

嗨@Helix我完成了你的建议,但是现在我的线性布局是在相对布局中彼此重叠并且不会排队一个在另一个之下,我会用屏幕截图更新我的问题 – Sjharrison