'Android ScrollView height
I have a problem making a ScrollView wrap the content.
I don't know why but the ScrollView's height is bigger then the content I have and I read about some way to fix this but they didn't work.
(layout_weight, fill_parents, wrap_content, android:fillViewport="true").
So I guess I have made a simple mistake in my code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/background"
android:orientation="vertical" >
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/title_bg"
android:gravity="center"
android:text="Profile"
android:textColor="#fff"
android:textSize="20sp" />
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fillViewport="true" >
<LinearLayout
android:id="@+id/LinearLayout01"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/background"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="@+id/TextView02"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:text="@string/mother"
android:textAppearance="? android:attr/textAppearanceMedium" />
<EditText
android:id="@+id/etMother"
android:layout_width="0sp"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginRight="8dp"
android:layout_marginTop="8dp"
android:layout_weight="1"
android:ems="10"
android:hint="@string/enter_your_name"
android:inputType="textPersonName" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<ToggleButton
android:id="@+id/tbDueDateLMP"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:background="@drawable/button_red"
android:checked="true"
android:textColor="#fff"
android:textOff="@string/due_date"
android:textOn="@string/lmp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<Button
android:id="@+id/bPlusDay"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="4dp"
android:layout_marginLeft="8dp"
android:layout_weight="1"
android:background="@drawable/button_blue"
android:onClick="onClick"
android:text="@string/plus"
android:textColor="#fff"
android:textSize="20sp"
android:textStyle="bold" />
<Button
android:id="@+id/bPlusMonth"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="4dp"
android:layout_marginLeft="8dp"
android:layout_weight="1"
android:background="@drawable/button_blue"
android:onClick="onClick"
android:text="@string/plus"
android:textColor="#fff"
android:textSize="20sp"
android:textStyle="bold" />
<Button
android:id="@+id/bPlusYear"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="4dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_weight="0.69"
android:background="@drawable/button_blue"
android:onClick="onClick"
android:text="@string/plus"
android:textColor="#fff"
android:textSize="20sp"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="@+id/tvDay"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_weight="1"
android:background="@drawable/black_back"
android:padding="3dp"
android:text="00"
android:textColor="#000"
android:textSize="59sp" />
<TextView
android:id="@+id/tvMonth"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_weight="1"
android:background="@drawable/black_back"
android:padding="3dp"
android:text="00"
android:textColor="#000"
android:textSize="59sp" />
<TextView
android:id="@+id/tvYear"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_weight="0.69"
android:background="@drawable/black_back"
android:padding="3dp"
android:text="0000"
android:textColor="#000"
android:textSize="59sp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<Button
android:id="@+id/bMinusDay"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginTop="4dp"
android:layout_weight="1"
android:background="@drawable/button_blue"
android:onClick="onClick"
android:text="@string/minus"
android:textColor="#fff"
android:textSize="20sp"
android:textStyle="bold" />
<Button
android:id="@+id/bMinusMonth"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginTop="4dp"
android:layout_weight="1"
android:background="@drawable/button_blue"
android:onClick="onClick"
android:text="@string/minus"
android:textColor="#fff"
android:textSize="20sp"
android:textStyle="bold" />
<Button
android:id="@+id/bMinusYear"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginTop="4dp"
android:layout_weight="0.69"
android:background="@drawable/button_blue"
android:onClick="onClick"
android:text="@string/minus"
android:textColor="#fff"
android:textSize="20sp"
android:textStyle="bold" />
</LinearLayout>
<Button
android:id="@+id/bProfileSave"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:background="@drawable/button_pink"
android:onClick="onClick"
android:text="@string/save"
android:textColor="#fff" />
<TextView
android:id="@+id/tvProfileInfo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#F00" />
</LinearLayout>
</ScrollView>
</LinearLayout>
thank you all.
Solution 1:[1]
You can try to set the top linear layout to wrap vertical content rather than fill parent, which make whole layout to use full height
Solution 2:[2]
I think the culprit is in android:fillViewport="true". If this is set then it will fill the view port even if there is not enough content to take up the space and even though you have the conflicting attribute android:layout_height="wrap_content". fillViewport takes precedence.
Solution 3:[3]
Can try to set the android:layout_height = "0dp"
It works like a charm
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Arcadien |
| Solution 2 | alphonzo79 |
| Solution 3 | Ehsan Rosdi |
