Android ScrollView not working properly

2019-01-25 18:03发布

问题:

I developed an android application in which the scroll-view is not scrolling.. I am posting the code here pls check and if found any error pls help.. Here I used Linear Layout as root and then Scroll-view and Relative Layout inside the scroll-view and ... text-views inside relative layout... but this is not scrolling up..

XML

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@color/orange"
    android:orientation="vertical" >


    <RelativeLayout
        android:id="@+id/header901"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/green"
        android:layout_marginLeft="5dp"
        android:layout_marginRight="5dp"
        android:layout_marginTop="5dp"
        android:gravity="center">


        <TextView 
            android:id="@+id/headertext901"
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:layout_margin="5dp"
            android:gravity="center"
            android:textColor="#ffffff"
            android:textSize="20sp"
            android:text="Result"
            android:textStyle="bold"
            />
        </RelativeLayout>


             <ScrollView
    android:id="@+id/scrollView901"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:scrollbars="vertical"
    android:fillViewport="true">




            <RelativeLayout
                android:id="@+id/lLayout901"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"

                android:orientation="vertical"
                 >



                <TextView
                    android:id="@+id/textView1"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentLeft="true"
                    android:layout_alignParentTop="true"
                    android:layout_marginLeft="16dp"
                    android:layout_marginTop="22dp"
                    android:text="Your Destiny number is :" />

                <TextView
                    android:id="@+id/textView2"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignBaseline="@+id/textView1"
                    android:layout_alignBottom="@+id/textView1"
                    android:layout_alignParentRight="true"
                    android:layout_marginRight="44dp"
                    android:text="TextView" />

                <TextView
                    android:id="@+id/textView3"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignLeft="@+id/textView1"
                    android:layout_below="@+id/textView1"
                    android:layout_marginTop="18dp"
                    android:text="Your result is loading......" />

                <TextView
                    android:id="@+id/textView4"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignLeft="@+id/textView3"
                    android:layout_below="@+id/textView3"
                    android:layout_marginTop="16dp"
                    android:text="Your Talent Number is :" />

                <TextView
                    android:id="@+id/textView5"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignBaseline="@+id/textView4"
                    android:layout_alignBottom="@+id/textView4"
                    android:layout_alignLeft="@+id/textView2"
                    android:text="TextView" />

                <TextView
                    android:id="@+id/textView6"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignLeft="@+id/textView4"
                    android:layout_below="@+id/textView4"
                    android:layout_marginTop="20dp"
                    android:text="Your result is loading......." />

                <TextView
                    android:id="@+id/textView7"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignLeft="@+id/textView6"
                    android:layout_below="@+id/textView6"
                    android:layout_marginTop="16dp"
                    android:text="Your Heart Number is :" />

                <TextView
                    android:id="@+id/textView8"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignBaseline="@+id/textView7"
                    android:layout_alignBottom="@+id/textView7"
                    android:layout_alignLeft="@+id/textView5"
                    android:text="TextView" />

                <TextView
                    android:id="@+id/textView9"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignLeft="@+id/textView7"
                    android:layout_centerVertical="true"
                    android:text="Your result is loading...." />

                <TextView
                    android:id="@+id/textView10"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignLeft="@+id/textView9"
                    android:layout_below="@+id/textView9"
                    android:layout_marginTop="20dp"
                    android:text="Your Personality number is :" />

                <TextView
                    android:id="@+id/textView11"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignBottom="@+id/textView10"
                    android:layout_alignLeft="@+id/textView8"
                    android:text="TextView" />

                <TextView
                    android:id="@+id/textView12"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignLeft="@+id/textView10"
                    android:layout_below="@+id/textView10"
                    android:layout_marginTop="18dp"
                    android:text="Your result is loading...." />

                <TextView
                    android:id="@+id/textView13"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignLeft="@+id/textView12"
                    android:layout_below="@+id/textView12"
                    android:layout_marginTop="18dp"
                    android:text="Your Minor expression no:" />

                <TextView
                    android:id="@+id/textView14"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignBottom="@+id/textView13"
                    android:layout_alignLeft="@+id/textView11"
                    android:text="TextView" />

                <TextView
                    android:id="@+id/textView15"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignLeft="@+id/textView13"
                    android:layout_below="@+id/textView13"
                    android:layout_marginTop="18dp"
                    android:text="Your result is loading....." />

                <TextView
                    android:id="@+id/textView16"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignLeft="@+id/textView15"
                    android:layout_below="@+id/textView15"
                    android:layout_marginTop="18dp"
                    android:text="Your Minor Heart Desire no:" />

                <TextView
                    android:id="@+id/textView17"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignBottom="@+id/textView16"
                    android:layout_alignLeft="@+id/textView14"
                    android:text="TextView" />

                <TextView
                    android:id="@+id/textView18"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignLeft="@+id/textView16"
                    android:layout_below="@+id/textView16"
                    android:layout_marginTop="18dp"
                    android:text="Your result is loading....." />

                <TextView
                    android:id="@+id/textView19"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignLeft="@+id/textView18"
                    android:layout_below="@+id/textView18"
                    android:layout_marginTop="18dp"
                    android:text="Your Minor Personality no:" />

                <TextView
                    android:id="@+id/textView20"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignBottom="@+id/textView19"
                    android:layout_alignLeft="@+id/textView17"
                    android:text="TextView" />

                <TextView
                    android:id="@+id/textView21"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignLeft="@+id/textView19"
                    android:layout_below="@+id/textView19"
                    android:layout_marginTop="18dp"
                    android:text="Your result is loading....." />




                </RelativeLayout>
                </ScrollView>




</LinearLayout>

回答1:

You have used fill parent for your Scrollview height layout Use android:layout_height="wrap_content" for scrollview

And i am sugesting to use LinearLayout with vertical orientation layout for this kind of use



回答2:

Remove RelativeLayout with id "header901", it is useless, you can just leave headertext901 withe the main LinearLayout as parent ...

Then remove the following tags from SCrollView :

android:scrollbars="vertical"
android:fillViewport="true"

I would also advise to replace your RelativeLayout with id "lLayout901" by a LinearLayout, and follow @Martin Marconcini's advice to replace fill_parent with match_parent.