Reputation: 103
I'm making an app for Android device and I'm trying to have a ScrollView inside a LinearLayout but when I try to do this the ScrollView take all the space and elements who are after the ScrollView in the LinearLayout disapear.
For example:
If the ScrollView is not "full":
If the ScrollView is "full":
As you can see the button disapear...
Here is the code of this Activity:
<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>
After I add elements in the LinearLayout who are in the ScrollView.
Any solution?
Thanks.
Upvotes: 6
Views: 38889
Reputation: 13747
you had android:layout_height="wrap_content"
as your height. that means that the height is as high as the content inside it. if you dont want it to take the whole place you can give it weight (like the answer above) or you can set your hight with dp. for example:
<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" />
as you can see i gave the linear layout a "sum" and all of his children are given weight. is it clear? is it what you needed?
Upvotes: 2
Reputation: 1893
Try the following:
android:layout_height="0dp"
android:layout_weight="1"
This tells your ScrollView to take all the remaining space not occupied by the other elements.
Upvotes: 10