Search code examples
androidandroid-scrollview

ScrollView not working in my view


I wish to make my view scrollable but its not working. I have checked but couldn't find the problem. However, the scrollview is visible in some portion of the screen, but the last button is never shown.
Here's code:

<ScrollView 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"
    android:orientation="vertical"
    android:padding="@dimen/margin_default"
    android:background="@color/ThemeColor"
    tools:context=".AuthActivityFragment"
    >
    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical"
        android:layout_marginTop="32dp"
        android:layout_marginBottom="32dp"
        >
    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:src="@mipmap/logo_large"
        />
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:background="@mipmap/login_form_bg"
        android:padding="20dp"
        android:gravity="center"
        android:layout_margin="10dp"
        >
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/heading_login"
            android:layout_gravity="center"
            android:textColor="@color/black_shade"
            style="@android:style/TextAppearance.DeviceDefault.Medium"
            android:textStyle="bold"
            />
        <EditText android:hint="@string/hint_login_username"
            android:id="@+id/etEmail"
            android:textColorHint="@color/light_grey_hint"
            android:singleLine="true"
            android:inputType="textEmailAddress"
            android:layout_gravity="center"
            android:layout_width="match_parent"
            android:layout_height="48dp"
            android:layout_margin="@dimen/margin_default"
            android:background="@drawable/border_fields"
            style="@android:style/TextAppearance.DeviceDefault.Medium"
            android:paddingBottom="@dimen/margin_default"
            android:paddingTop="@dimen/margin_default"
            android:paddingLeft="@dimen/large_margins"
            android:paddingRight="@dimen/large_margins"
            />
        <EditText android:hint="@string/hint_login_password"
            android:id="@+id/etPassword"
            android:textColorHint="@color/light_grey_hint"
            android:singleLine="true"
            android:layout_gravity="center"
            android:layout_width="match_parent"
            android:layout_height="48dp"
            android:background="@drawable/border_fields"
            style="@android:style/TextAppearance.DeviceDefault.Medium"
            android:paddingBottom="@dimen/margin_default"
            android:paddingTop="@dimen/margin_default"
            android:paddingLeft="@dimen/large_margins"
            android:paddingRight="@dimen/large_margins"
            android:layout_margin="@dimen/margin_default"
            android:inputType="textPassword"
            android:ems="10"
            />
    </LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        >
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:gravity="center"
            android:padding="@dimen/margin_default"
            >
            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@mipmap/ic_small_cross"
                android:layout_gravity="center_vertical"
                android:padding="@dimen/large_margins"
                />
            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@mipmap/ic_small_cross"
                android:layout_gravity="center_vertical"
                android:padding="@dimen/large_margins"
                />
        <ImageButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/btnLogin"
            android:background="@mipmap/login"
            android:layout_marginRight="@dimen/margin_default"
            android:layout_gravity="center_vertical"
            />

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@mipmap/ic_small_cross"
                android:padding="@dimen/large_margins"
                android:layout_gravity="center_vertical"
                />
            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@mipmap/ic_small_cross"
                android:padding="@dimen/large_margins"
                android:layout_gravity="center_vertical"
                />

        </LinearLayout>
    </LinearLayout>
    <ImageButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/btnSignUp"
        android:background="@mipmap/signup"
        android:layout_marginRight="@dimen/margin_default"
        android:layout_gravity="center_horizontal"
        />
</LinearLayout>
</ScrollView>

Solution

  • Everything with ScrollView is fine.

    android:layout_marginTop="32dp"
            android:layout_marginBottom="32dp"<br>
    

    This piece of code is your evil. Since you have given margin to first child, its not showing full content.Change it to

    android:paddingBottom="32dp"
            android:paddingTop="32dp"