-3

I have created an android quiz app which has a ScrollView. The problem is when you scroll down it goes back up automatically so users cannot choose the answer at the bottom. How do I fix this?

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:ads="http://schemas.android.com/apk/res-auto"
    android:id="@+id/relatively"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@drawable/add"
    android:orientation="vertical"
    android:weightSum="1" >

    <ScrollView
        android:layout_width="wrap_content"
        android:layout_height="292dp"
        android:id="@+id/scrollView"
        android:layout_gravity="center_horizontal"
        android:layout_weight="0.20">

        <LinearLayout
            android:id="@+id/linearLayout1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="0.90"
            android:orientation="vertical"
            android:weightSum="1" >

            <LinearLayout
                android:id="@+id/linearLayout11"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_weight="0.20"
                android:orientation="horizontal"
                android:weightSum="1" >

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:orientation="horizontal" >

                    <TextView
                        android:id="@+id/score"
                        android:layout_width="160dp"
                        android:layout_height="wrap_content"
                        android:layout_centerHorizontal="true"
                        android:layout_marginRight="10dp"
                        android:gravity="center"
                        android:text="Maraga : 0"
                        android:textColor="#bc42f4"
                        android:textSize="25.0sp"
                        android:textStyle="bold" />

                    <TextView
                        android:id="@+id/timers"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_centerHorizontal="true"
                        android:layout_marginRight="10dp"
                        android:layout_weight="1"
                        android:gravity="center"
                        android:text="00:00:49"
                        android:textColor="#ab0afb"
                        android:textSize="25.0sp"
                        android:textStyle="bold"
                        android:textIsSelectable="true" />
                </LinearLayout>
            </LinearLayout>

            <LinearLayout
                android:id="@+id/linearLayout12"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_weight=".8"
                android:orientation="vertical"
                android:weightSum="1" >

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_weight="0.40" >

                    <TextView
                        android:id="@+id/txtQuestion"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_centerHorizontal="true"
                        android:layout_gravity="center"
                        android:layout_marginTop="5dp"
                        android:gravity="center"
                        android:text="15*2*1-1"
                        android:textColor="#fd0213"
                        android:textSize="35.0sp"
                        android:textStyle="bold" />
                </LinearLayout>

                <LinearLayout
                    android:layout_width="295dp"
                    android:layout_height="381dp"
                    android:orientation="vertical"
                    android:weightSum="1"
                    android:gravity="fill_horizontal|start|end|center_horizontal"
                    android:layout_gravity="center_horizontal">

                    <Button
                        android:id="@+id/button1"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center"
                        android:layout_marginTop="20dp"
                        android:background="#09bcf8"
                        android:gravity="center"
                        android:text="30"
                        android:textColor="#ffffff"
                        android:textSize="25.0sp" />

                    <Button
                        android:id="@+id/button2"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center"
                        android:layout_marginTop="20dp"
                        android:background="#2cf309"
                        android:gravity="center"
                        android:text="29"
                        android:textColor="#ffffff"
                        android:textSize="25.0sp" />

                    <Button
                        android:id="@+id/button3"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center"
                        android:layout_marginTop="20dp"
                        android:background="#7f0af4"
                        android:gravity="center"
                        android:text="32"
                        android:textColor="#ffffff"
                        android:textSize="25.0sp" />

                </LinearLayout>


            </LinearLayout>


        </LinearLayout>
    </ScrollView>

    <com.google.android.gms.ads.AdView
        android:id="@+id/adView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_alignParentBottom="true"
        ads:adSize="SMART_BANNER"

        ads:adUnitId="@string/banner_ad_unit_id"
        android:layout_weight="1.5"
        android:transitionGroup="false">
    </com.google.android.gms.ads.AdView>


</LinearLayout>
cf-
  • 8,598
  • 9
  • 36
  • 58

2 Answers2

0

Remove this line: android:layout_weight="0.20" in your Scrollview.

Praveen Singh
  • 116
  • 1
  • 10
0

Try this code i was changed so many things in your code

You taken so many unnecessary layouts. make sure next time you create view with as less layout possible. because its make load on graphics.

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/scrollView"
    android:orientation="vertical"
    android:fillViewport="true"
    android:layout_gravity="center_horizontal">

    <LinearLayout
        android:id="@+id/linearLayout1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:weightSum="1"
         >
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:paddingLeft="30dp"
            android:paddingRight="30dp"
            android:layout_weight="0.80"
            android:orientation="vertical">

        <LinearLayout
            android:id="@+id/linearLayout11"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:weightSum="1"
            android:orientation="horizontal">
                <TextView
                    android:id="@+id/score"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:gravity="center"
                    android:text="Maraga : 0"
                    android:layout_weight="0.5"
                    android:textColor="#bc42f4"
                    android:textSize="25.0sp"
                    android:textStyle="bold" />

                <TextView
                    android:id="@+id/timers"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_centerHorizontal="true"
                    android:layout_marginRight="10dp"
                    android:layout_weight="0.5"
                    android:gravity="center"
                    android:text="00:00:49"
                    android:textColor="#ab0afb"
                    android:textSize="25.0sp"
                    android:textStyle="bold"
                    android:textIsSelectable="true" />
            </LinearLayout>


                <TextView
                    android:id="@+id/txtQuestion"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:layout_marginTop="5dp"
                    android:gravity="center"
                    android:text="15*2*1-1"
                    android:textColor="#fd0213"
                    android:textSize="35.0sp"
                    android:textStyle="bold" />


                <Button
                    android:id="@+id/button1"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:layout_marginTop="20dp"
                    android:background="#09bcf8"
                    android:gravity="center"
                    android:text="30"
                    android:textColor="#ffffff"
                    android:textSize="25.0sp" />

                <Button
                    android:id="@+id/button2"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:layout_marginTop="20dp"
                    android:background="#2cf309"
                    android:gravity="center"
                    android:text="29"
                    android:textColor="#ffffff"
                    android:textSize="25.0sp" />

                <Button
                    android:id="@+id/button3"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:layout_marginTop="20dp"
                    android:background="#7f0af4"
                    android:gravity="center"
                    android:text="32"
                    android:textColor="#ffffff"
                    android:textSize="25.0sp" />


        </LinearLayout>
        <com.google.android.gms.ads.AdView
            android:id="@+id/adView"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            ads:adSize="SMART_BANNER"
            ads:adUnitId="@string/banner_ad_unit_id"
            android:layout_weight="0.20"
            android:transitionGroup="false">
        </com.google.android.gms.ads.AdView>
    </LinearLayout>


</ScrollView>
Vishal Thakkar
  • 2,117
  • 2
  • 16
  • 33