简体   繁体   中英

Scroll View not scrolling with relative layout

I am busy with an android application and i cant seem to get the scrollView working with my relative layout. I am relatively new to android and this is the first time i am using scroll view. Here is my xml:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="2000dp"
    android:background="@drawable/background">

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">

        <android.support.design.widget.FloatingActionButton
            android:id="@+id/fab"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentEnd="true"
            android:layout_below="@+id/fPrice"
            android:layout_gravity="bottom|end"
            android:layout_marginEnd="39dp"
            app:srcCompat="@drawable/ic_skip_previous_black_24dp" />

        <EditText
            android:id="@+id/fid"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:layout_alignStart="@+id/fName"
            android:layout_marginTop="20dp"
            android:ems="10"
            android:hint="Fabric ID"
            android:inputType="number"
            android:letterSpacing="0.1"
            android:textColor="#fff"
            android:textColorHint="#fff" />

        <EditText
            android:id="@+id/fName"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentStart="true"
            android:layout_below="@+id/fid"
            android:layout_marginStart="32dp"
            android:layout_marginTop="45dp"
            android:ems="10"
            android:hint="Fabric Name"
            android:letterSpacing="0.1"
            android:textColor="#fff"
            android:textColorHint="#fff" />

        <EditText
            android:id="@+id/fRange"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignStart="@+id/fName"
            android:layout_below="@+id/fName"
            android:layout_marginTop="36dp"
            android:ems="10"
            android:hint="Fabric Range"
            android:letterSpacing="0.1"
            android:textColor="#fff"
            android:textColorHint="#fff" />

        <EditText
            android:id="@+id/fSupplier"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignStart="@+id/fRange"
            android:layout_below="@+id/fRange"
            android:layout_marginTop="29dp"
            android:ems="10"
            android:hint="Fabric Supplier"
            android:letterSpacing="0.1"
            android:textColor="#fff"
            android:textColorHint="#fff" />

        <EditText
            android:id="@+id/fWidth"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignEnd="@+id/fSupplier"
            android:layout_below="@+id/fSupplier"
            android:layout_marginTop="37dp"
            android:ems="10"
            android:hint="Fabric Width"
            android:inputType="number"
            android:letterSpacing="0.1"
            android:textColor="#fff"
            android:textColorHint="#fff" />

        <EditText
            android:id="@+id/fStyle"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignStart="@+id/fWidth"
            android:layout_below="@+id/fWidth"
            android:layout_marginTop="19dp"
            android:ems="10"
            android:hint="Fabric Style"
            android:inputType="text"
            android:letterSpacing="0.1"
            android:textColor="#fff"
            android:textColorHint="#fff" />

        <EditText
            android:id="@+id/fPattern"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignEnd="@+id/fStyle"
            android:layout_below="@+id/fStyle"
            android:layout_marginTop="37dp"
            android:ems="10"
            android:hint="Fabric Pattern repeat"
            android:inputType="number"
            android:letterSpacing="0.1"
            android:textColor="#fff"
            android:textColorHint="#fff" />

        <EditText
            android:id="@+id/fPrice"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignStart="@+id/fPattern"
            android:layout_below="@+id/fPattern"
            android:layout_marginTop="32dp"
            android:ems="10"
            android:hint="Fabric Unit Price"
            android:inputType="number"
            android:letterSpacing="0.1"
            android:textColor="#fff"
            android:textColorHint="#fff" />

        <Button
            android:id="@+id/button22"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignStart="@+id/fPrice"
            android:layout_below="@+id/fPrice"
            android:layout_marginTop="33dp"
            android:layout_weight="1"
            android:background="@drawable/border"
            android:gravity="center"
            android:text="Add Rail"
            android:textColor="#fff"
            android:textStyle="bold" />

        <ProgressBar
            android:id="@+id/progressBar12"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_marginEnd="63dp"
            android:layout_toStartOf="@+id/fab" />



    </RelativeLayout>

    </ScrollView >

In the above code, I have a scroll view with a child Relative layout. Could someone please help me solve this problem

The Direct Child Layout to ScrollView height must not be match parent. If the child's height is more than scrollview height than only Scroll will work.

In your case you have used RelativeLayout as Child layout to ScrollView and put its height as match parent.

I suggest to use LinearLayout instead (Recommendation) and set View height as wrapcontent.

Along with that in your case set ScrollView height MatchParent.

That will resolve your problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM