So I have a ScrollView with a LinearLayout within it. It seems that when I attempt to scroll to the bottom of my linearlayout, the bottom ~5 dip is cut off (ie bottom margin) I think it might have something to do with my linearlayout's 5dip margin?
Here's activity_create_account.xml
:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:background="@drawable/grey"
android:orientation="vertical"
android:padding="0dp"
tools:context=".Login" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:weightSum="100"
android:orientation="vertical">
<!-- BEGIN HEADER -->
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:background="@drawable/titlebar"
android:orientation="horizontal"
android:padding="8dip" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:padding="0dp"
android:text="create account"
android:textColor="#FFFFFF"
android:textSize="32sp"
android:textStyle="bold"
android:typeface="sans" />
</LinearLayout>
<!-- END HEADER -->
<!-- BEGIN BODY -->
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="top"
android:orientation="vertical">
<LinearLayout
android:id="@+id/innerLinearLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="10dip"
android:background="@drawable/rounded_white"
android:orientation="vertical"
android:padding="5dip" >
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="textEmailAddress"
android:ems="10"
android:id="@+id/etCreateEmail"
android:hint="Email"
android:layout_weight="1"
android:paddingTop="8dip"
android:paddingBottom="8dip"
android:paddingRight="8dip"
android:paddingLeft="8dip"
android:layout_marginBottom="4dip"
android:layout_marginTop="5dip"/>
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="textEmailAddress"
android:ems="10"
android:id="@+id/etCreateEmail"
android:hint="Email"
android:layout_weight="1"
android:paddingTop="8dip"
android:paddingBottom="8dip"
android:paddingRight="8dip"
android:paddingLeft="8dip"
android:layout_marginBottom="4dip"
android:layout_marginTop="5dip"/>
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="textEmailAddress"
android:ems="10"
android:id="@+id/etCreateEmail"
android:hint="Email"
android:layout_weight="1"
android:paddingTop="8dip"
android:paddingBottom="8dip"
android:paddingRight="8dip"
android:paddingLeft="8dip"
android:layout_marginBottom="4dip"
android:layout_marginTop="5dip"/>
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="textEmailAddress"
android:ems="10"
android:id="@+id/etCreateEmail"
android:hint="Email"
android:layout_weight="1"
android:paddingTop="8dip"
android:paddingBottom="8dip"
android:paddingRight="8dip"
android:paddingLeft="8dip"
android:layout_marginBottom="4dip"
android:layout_marginTop="5dip"/>
<EditText
android:id="@+id/etChooseUsername"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="4dip"
android:layout_weight="1"
android:ems="10"
android:hint="Choose a username"
android:inputType="text"
android:paddingBottom="8dip"
android:paddingLeft="8dip"
android:paddingRight="8dip"
android:paddingTop="8dip" />
<EditText
android:id="@+id/etChoosePassword"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="4dip"
android:layout_weight="1"
android:ems="10"
android:hint="Choose a password"
android:inputType="textPassword"
android:paddingBottom="8dip"
android:paddingLeft="8dip"
android:paddingRight="8dip"
android:paddingTop="8dip" />
<EditText
android:id="@+id/etRetypePassword"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="4dip"
android:layout_weight="1"
android:ems="10"
android:hint="Re-type password"
android:inputType="textPassword"
android:paddingBottom="8dip"
android:paddingLeft="8dip"
android:paddingRight="8dip"
android:paddingTop="8dip" />
<Button
android:id="@+id/bCreateAccountConfirm"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_weight="1"
android:background="@drawable/button_selector"
android:padding="0dip"
android:text="Create Account"
android:textColor="#ffffff"
android:textStyle="bold"
android:typeface="sans" />
</LinearLayout>
</ScrollView>
<!-- END BODY -->
Here's what it looks like when I try to scroll all the way down (there's supposed to be a slim section of white beneath the button & then a slim section of grey margin)
This can also be done with a linear layout. Just provide Height = 0dp and weight = 1 in the layout above, and the one you want at the bottom is just write height = line feed content, not weight.
Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main. xml. In this above code, we have declare Linear layout as parent and added Vertical Scroll view.
In Android, a ScrollView is a view group that is used to make vertically scrollable views. A scroll view contains a single direct child only. In order to place multiple views in the scroll view, one needs to make a view group(like LinearLayout) as a direct child and then we can define many views inside it.
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
really solved the issue for me, no NestedView or padding is required. Keep ScrollView's direct child view's layout_height as "wrapped_content" though.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With