2012-08-26 62 views
6

我正在为Android设备制作应用程序,我正在尝试在LinearLayout中使用ScrollView,但是当我尝试执行此操作时,ScrollView将获取ScrollView之后的所有空间和元素在LinearLayout中不起作用。Android:垂直LinearLayout的滚动视图

例如:
如果滚动型是不是 “全”:
http://kakko76.free.fr/scroll2.jpg
如果滚动型是 “充分”:
http://kakko76.free.fr/scroll1.png

正如你可以看到按钮disapear ...
以下是此活动的代码:

<LinearLayout 
    android:id="@+id/linearLayout1" 
    android:layout_width="fill_parent" 
    android:layout_marginLeft="50dp" 
    android:layout_height="wrap_content" 
    android:layout_centerHorizontal="true" 
    android:layout_centerVertical="true" 
    android:orientation="vertical" 
    android:focusable="true" 
    android:focusableInTouchMode="true" 
    android:background="@drawable/linearlayoutbackground" > 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="@string/nom_des_joueurs" 
     android:textAppearance="?android:attr/textAppearanceLarge" 
     android:layout_marginBottom="30dp" /> 

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

     <LinearLayout 
      android:id="@+id/llPlayersName" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:orientation="vertical" 
      > 

     </LinearLayout> 

    </ScrollView> 

    <Button 
     android:id="@+id/okPlayersName" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:text="@string/ok" 
     android:background="@drawable/backgroundbutton" 
     android:layout_marginTop="30dp" /> 
</LinearLayout> 

在添加Linea中的元素后rLayout谁在ScrollView中。
任何解决方案?
谢谢。

回答

9

尝试以下操作:

android:layout_height="0dp" 
android:layout_weight="1" 

这告诉你的滚动型采取一切不被其他元素所占据的剩余空间。

+1

正在写相同的解决方案在同一时间:-p你更快.. –

+0

谢谢你的工作:) – kakko76

1

你有android:layout_height="wrap_content"作为你的身高。这意味着高度与其中的内容一样高。如果你不想让它占据整个地方,你可以给它重量(如上面的答案),或者你可以用dp来设置你的高度。例如:

<LinearLayout 
android:id="@+id/linearLayout1" 
android:layout_width="fill_parent" 
android:layout_marginLeft="50dp" 
android:layout_height="wrap_content" 
android:layout_centerHorizontal="true" 
android:layout_centerVertical="true" 
android:orientation="vertical" 
android:focusable="true" 
android:focusableInTouchMode="true" 
android:background="@drawable/linearlayoutbackground" 
android:weightSum="1.5" > 

<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="0dp" 
    android:layout_weight = "0.2" 
    android:text="@string/nom_des_joueurs" 
    android:textAppearance="?android:attr/textAppearanceLarge" 
    android:layout_marginBottom="30dp" /> 

<ScrollView 
    android:id="@+id/scrollView1" 
    android:layout_width="match_parent" 
    android:layout_height="0dp" 
    android:layout_weight = "1"> 

    <LinearLayout 
     android:id="@+id/llPlayersName" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="vertical" 
     > 

    </LinearLayout> 

</ScrollView> 

<Button 
    android:id="@+id/okPlayersName" 
    android:layout_width="match_parent" 
    android:layout_height="0" 
    android:layout_weight = "0.3"> 
    android:text="@string/ok" 
    android:background="@drawable/backgroundbutton" 
    android:layout_marginTop="30dp" /> 

,你可以看到我给的线性布局的“总和”,所有他的孩子们给出的重量。 是否清楚?你需要什么?