Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RelativeLayout with scrollview not scrolling

I'm working on fixing a bug in someone's code and I can't figure out how to get this to scroll correctly. I'm just trying to get the "question" area to scroll vertically. Currently it just grows and pushes everything down. Please help!

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:slide="http://schemas.android.com/apk/res/com.trivia.americanhistory"
    android:orientation="vertical" android:layout_width="fill_parent"
    android:layout_height="fill_parent" android:background="#000000">
    <Button android:id="@+id/ned_icon" android:layout_marginLeft="10dp"
        android:layout_marginTop="10dp" android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/ned_icon"
        android:layout_alignParentLeft="true"
        android:layout_marginBottom="5dp" />

    <Button android:id="@+id/menu" android:layout_margin="10dp"
        android:background="@drawable/menu"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_toRightOf="@+id/ned_icon" />
    <Button android:id="@+id/share"
        android:background="@drawable/share_btn"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_toRightOf="@+id/menu" android:layout_marginTop="10dp" />

    <RelativeLayout android:id="@+id/ned_character_layout"
        android:background="@drawable/ned_background"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true" android:layout_marginTop="10dp"
        android:layout_marginRight="5dp" android:layout_marginLeft="5dp">

        <ImageView android:id="@+id/ned_character_image"
            android:src="@drawable/ned"
            android:padding="2dp" android:layout_centerInParent="true" android:layout_height="140dp" android:layout_width="106dp"/>
    </RelativeLayout>

    <RelativeLayout android:id="@+id/question_layout"
        android:background="@drawable/question_bkgrd"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" android:layout_marginRight="5dp"
        android:layout_marginLeft="5dp" android:layout_below="@+id/ned_icon"
        android:layout_marginBottom="10dp">

        <ImageView android:id="@+id/q"
            android:background="@drawable/q_img"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" android:layout_marginTop="10dp"
            android:layout_marginLeft="10dp" android:layout_marginRight="2dp" />
        <ScrollView android:layout_height="wrap_content"
            android:layout_toRightOf="@+id/q" android:layout_marginTop="10dp"
            android:layout_width="150dp">
            <TextView android:id="@+id/question"
                android:text="Test annswer a Test annswer a Test annswer a Test annswer a Test annswer a Test annswer a "
                android:layout_height="wrap_content"
                android:layout_toRightOf="@+id/q" android:layout_marginTop="10dp"
                android:layout_width="150dp" android:textColor="#000000"
                android:textSize="18sp" android:textStyle="bold" />
        </ScrollView>


    </RelativeLayout>

    <RelativeLayout android:id="@+id/amount_layout"
        android:background="@drawable/plain_dollar_amt_bkgr"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" android:layout_marginRight="5dp"
        android:layout_marginLeft="5dp"
        android:layout_below="@+id/ned_character_layout"
        android:layout_alignParentRight="true"
        android:layout_marginTop="5dp">
        <ImageView android:layout_width="40dp" android:id="@+id/skull"
            android:layout_height="40dp" android:layout_alignParentTop="true"
            android:layout_centerHorizontal="true"
            android:background="@drawable/skull" android:visibility="invisible"/>

        <TextView android:layout_width="wrap_content"
            android:id="@+id/level_text" android:layout_height="wrap_content"
            android:layout_alignParentTop="true" android:layout_centerHorizontal="true" android:text="Level 0"/>

        <TextView android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/skull" android:text="Question 1/40"
            android:layout_centerHorizontal="true"   android:id="@+id/question_number"/>


    </RelativeLayout>



    <Button android:id="@+id/call_mama"
        android:background="@drawable/call_mama"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_above="@+id/answer_a_layout"
        android:layout_marginLeft="10dp" android:onClick="callMama" />
    <Button android:id="@+id/call_nina"
        android:background="@drawable/call_nina"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_above="@+id/answer_a_layout"
        android:layout_toRightOf="@+id/call_mama"
        android:layout_marginLeft="2dp" android:onClick="fiftyFifty" />
    <Button android:id="@+id/call_jed"
        android:background="@drawable/call_jed"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_above="@+id/answer_a_layout"
        android:layout_toRightOf="@+id/call_nina"
        android:layout_marginLeft="2dp" />

    <LinearLayout android:id="@+id/answer_a_layout"
        android:orientation="horizontal" android:layout_width="fill_parent"
        android:layout_height="wrap_content" android:layout_marginRight="5dp"
        android:layout_marginLeft="5dp"
        android:layout_below="@+id/question_layout"
        android:layout_marginTop="5dp" android:layout_marginBottom="2dp">
        <Button android:background="@drawable/ans_a"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" android:layout_marginTop="10dp"
            android:layout_margin="5dp" />
        <Button android:layout_margin="5dp"
            android:id="@+id/answer_a_mark" android:background="@drawable/cross"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" android:visibility="invisible" />
        <TextView android:layout_margin="5dp" android:id="@+id/answer_a"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" android:textColor="#ffffff"
            android:textSize="18sp" android:textStyle="bold" />

    </LinearLayout>
    <ImageView android:id="@+id/answer_a_line"
        android:background="@drawable/question_line"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/answer_a_layout"
        android:layout_centerHorizontal="true" />


    <LinearLayout android:id="@+id/answer_b_layout"
        android:orientation="horizontal" android:layout_width="fill_parent"
        android:layout_height="wrap_content" android:layout_marginRight="5dp"
        android:layout_marginLeft="5dp"
        android:layout_below="@+id/answer_a_line"
        android:layout_marginTop="5dp" android:layout_marginBottom="2dp">
        <Button android:layout_margin="5dp"
            android:background="@drawable/ans_b"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
        <Button android:layout_margin="5dp"
            android:id="@+id/answer_b_mark" android:background="@drawable/cross"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" android:visibility="invisible" />
        <TextView android:layout_margin="5dp" android:id="@+id/answer_b"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" android:textColor="#ffffff"
            android:textSize="18sp" android:textStyle="bold" />

    </LinearLayout>
    <ImageView android:id="@+id/answer_b_line"
        android:background="@drawable/question_line"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/answer_b_layout"
        android:layout_centerHorizontal="true" />

    <LinearLayout android:id="@+id/answer_c_layout"
        android:orientation="horizontal" android:layout_width="fill_parent"
        android:layout_height="wrap_content" android:layout_marginRight="5dp"
        android:layout_marginLeft="5dp"
        android:layout_below="@+id/answer_b_line"
        android:layout_marginTop="5dp" android:layout_marginBottom="2dp">
        <Button android:layout_margin="5dp"
            android:background="@drawable/ans_c"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
        <Button android:layout_margin="5dp"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/cross" android:visibility="invisible"
            android:id="@+id/answer_c_mark" />
        <TextView android:layout_margin="5dp" android:id="@+id/answer_c"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" android:textColor="#ffffff"
            android:textSize="18sp" android:textStyle="bold" />

    </LinearLayout>
    <ImageView android:id="@+id/answer_c_line"
        android:background="@drawable/question_line"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/answer_c_layout"
        android:layout_centerHorizontal="true" />


    <LinearLayout android:id="@+id/answer_d_layout"
        android:orientation="horizontal" android:layout_width="fill_parent"
        android:layout_height="wrap_content" android:layout_marginRight="5dp"
        android:layout_marginLeft="5dp"
        android:layout_below="@+id/answer_c_line"
        android:layout_marginTop="5dp" android:layout_marginBottom="2dp">
        <Button android:layout_margin="5dp"
            android:background="@drawable/ans_d"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
        <Button android:layout_margin="5dp"
            android:id="@+id/answer_d_mark" android:background="@drawable/cross"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" android:visibility="invisible" />
        <TextView android:layout_margin="5dp" android:id="@+id/answer_d"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" android:textColor="#ffffff"
            android:textSize="18sp" android:textStyle="bold" />

    </LinearLayout>
    <ImageView android:id="@+id/answer_d_line"
        android:background="@drawable/question_line"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/answer_d_layout"
        android:layout_centerHorizontal="true" />


    <Button android:layout_margin="10dp" android:id="@+id/flag_it"
        android:background="@drawable/flag_it"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/answer_d_line" />
    <TextView android:layout_margin="10dp" android:id="@+id/count_down"
        android:text="29" android:textSize="25dp"
        android:layout_toRightOf="@+id/flag_it"
        android:layout_below="@+id/answer_d_line"
        android:layout_height="wrap_content" android:layout_width="35dp"
        android:gravity="center" />

    <Button android:layout_margin="10dp" android:id="@+id/next_question"
        android:background="@drawable/next_question"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/answer_d_line"
        android:layout_toRightOf="@+id/count_down" />


    <RelativeLayout android:layout_width="fill_parent"
        android:layout_height="48dip" android:background="#000000"
        android:id="@+id/ads" android:layout_alignParentBottom="true">
        <com.admob.android.ads.AdView android:id="@+id/ad"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent" slide:backgroundColor="#000000"
            slide:textColor="#ffffff" slide:testing="true"
            android:layout_gravity="bottom"
            slide:keywords="Android applications "
            android:layout_alignParentBottom="true" />


    </RelativeLayout>

</RelativeLayout>
like image 850
Josh Avatar asked Nov 30 '11 04:11

Josh


2 Answers

That is because you set the height of the ScrollView to wrap_content. Try giving it a fixed height or using a LinearLayout with weight so it fills the space left over from the other views.

like image 139
skynet Avatar answered Oct 17 '22 06:10

skynet


If you do not want to set it to a specific height, you can also add

android:fillViewport="true"

to your ScrollView

like image 26
finstas Avatar answered Oct 17 '22 05:10

finstas