Search code examples
androidscrollscrollviewandroid-linearlayoutandroid-relativelayout

Scrollview that doesn't scroll


In order to view all the elements inside my relativelayout in smaller screens, I have made the choice to use a scrollview to make it possible (or at least to try to accomplish this). The problem: I'm unable to scroll. The result of having or not the scrollview is the same, if the screen is small some elements will get cut off (this was fine if scroll was possible). In some searches I have come across some scrollview with linearlayout implementations, but in my case I think it's not very good, because i need check boxes aligned to the right of text.

Heres the xml of what I got thus far:

<ScrollView
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#231E1A"
    android:keepScreenOn="true"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:ignore="ContentDescription"
    android:fillViewport="true">

<RelativeLayout
    android:orientation="vertical"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" >

    <Button
        android:id="@+id/btn_getDirections"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:text="@string/btn_getDirections" />

    <TextView
        android:id="@+id/static_language"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_above="@+id/radioGroup"
        android:layout_alignLeft="@+id/radioGroup"
        android:text="@string/static_language"
        android:paddingTop="10dp"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:textColor="#FFFFFF" />

    <AutoCompleteTextView
        android:id="@+id/aComplete_destination"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_above="@+id/static_language"
        android:layout_alignLeft="@+id/static_language"
        android:ems="10"
        android:inputType="textNoSuggestions"
        android:text="@string/aComplete_destination" />


    <TextView
        android:id="@+id/static_destination"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_above="@+id/aComplete_destination"
        android:layout_alignLeft="@+id/aComplete_destination"
        android:text="@string/static_destination"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:textColor="#FFFFFF" />

    <TextView
        android:id="@+id/static_highways"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_above="@+id/static_destination"
        android:layout_alignLeft="@+id/static_destination"
        android:paddingBottom="10dp"
        android:text="@string/static_highways"
        android:textColor="#FFFFFF"
        android:textSize="20sp" />

    <TextView
        android:id="@+id/static_tolls"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_above="@+id/static_highways"
        android:layout_alignLeft="@+id/static_highways"
        android:paddingBottom="10dp"
        android:paddingTop="10dp"
        android:text="@string/static_tolls"
        android:textColor="#FFFFFF"
        android:textSize="20sp" />

    <TextView
        android:id="@+id/static_useCurrentLocation"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_above="@+id/static_tolls"
        android:layout_alignLeft="@+id/static_tolls"
        android:paddingTop="10dp"
        android:text="@string/static_useCurrentLocation"
        android:textColor="#FFFFFF"
        android:textSize="20sp" />

    <AutoCompleteTextView
        android:id="@+id/aComplete_origin"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_above="@+id/static_useCurrentLocation"
        android:layout_alignLeft="@+id/static_useCurrentLocation"
        android:ems="10"
        android:inputType="textNoSuggestions"
        android:text="@string/aComplete_origin" >
        <requestFocus />
    </AutoCompleteTextView>

    <TextView
        android:id="@+id/static_origin"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_above="@+id/aComplete_origin"
        android:layout_alignLeft="@+id/aComplete_origin"
        android:text="@string/static_origin"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:textColor="#FFFFFF" />

    <ImageView
        android:id="@+id/logo"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_above="@+id/static_origin"
        android:layout_alignLeft="@+id/static_origin"
        android:layout_alignParentTop="true"
        android:paddingBottom="10dp"
        android:scaleType="fitStart"
        android:src="@drawable/logo" />

    <CheckBox
        android:id="@+id/tolls_checkbox"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBaseline="@+id/static_tolls"
        android:layout_alignBottom="@+id/static_tolls"
        android:layout_alignParentRight="true"
        android:text="@string/checkbox" />

    <CheckBox
        android:id="@+id/highways_checkbox"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBaseline="@+id/static_highways"
        android:layout_alignBottom="@+id/static_highways"
        android:layout_alignParentRight="true"
        android:text="@string/checkbox" />

    <CheckBox
        android:id="@+id/useLocation_checkbox"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBaseline="@+id/static_useCurrentLocation"
        android:layout_alignBottom="@+id/static_useCurrentLocation"
        android:layout_alignParentRight="true"
        android:text="@string/checkbox" />

    <RadioGroup
        android:id="@+id/radioGroup"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_above="@+id/btn_getDirections"
        android:layout_alignLeft="@+id/btn_getDirections"
        android:orientation="horizontal" >

        <RadioButton
            android:id="@+id/radio_english"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:checked="true"
            android:textColor="#FFFFFF"
            android:layout_marginRight="20dp"
            android:text="@string/radio_english" />

        <RadioButton
            android:id="@+id/radio_portugues"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textColor="#FFFFFF"
            android:text="@string/radio_portugues" />
    </RadioGroup>
</RelativeLayout>
</ScrollView>

Solution

  • Huzzah! I got it to work! It was all a combination, of linearlayout, scrollview and relativelayout were was needed. Now it scrolls perfectly when the screen its not big enough to view the full content. I'm guessing that changing to linearlayout, was in fact the key in this. Basically i applied what was stated in developer site: http://developer.android.com/reference/android/widget/ScrollView.html

    A child that is often used is a LinearLayout in a vertical orientation, presenting a vertical array of top-level items that the user can scroll through.

    The xml:

    <ScrollView
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="#231E1A"
        android:keepScreenOn="true"
        android:scrollbars="none"
        android:overScrollMode="never"
        android:paddingBottom="@dimen/activity_vertical_margin"
        android:paddingLeft="@dimen/activity_horizontal_margin"
        android:paddingRight="@dimen/activity_horizontal_margin"
        android:paddingTop="@dimen/activity_vertical_margin"
        tools:ignore="ContentDescription"
        android:fillViewport="true">
    
    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="bottom"
        android:keepScreenOn="true"
        android:orientation="vertical" >
    
        <ImageView 
            android:layout_width="wrap_content"
            android:layout_height="80dp"
            android:id="@+id/logo"
            android:scaleType="fitStart"
            android:src="@drawable/logo"/>
    
        <TextView
            android:id="@+id/static_origin"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/static_origin"
            android:paddingTop="10dp"
            android:textAppearance="?android:attr/textAppearanceLarge"
            android:textColor="#FFFFFF" />
    
        <AutoCompleteTextView
            android:id="@+id/aComplete_origin"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:ems="10"
            android:inputType="textNoSuggestions"
            android:text="@string/aComplete_origin" >  
            <requestFocus />
        </AutoCompleteTextView>
    
        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content" >
    
            <TextView
                android:id="@+id/static_useCurrentLocation"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentLeft="true"
                android:layout_alignParentTop="true"
                android:textColor="#FFFFFF"
                android:textSize="20sp"
                android:paddingTop="10dp"
                android:text="@string/static_useCurrentLocation" />
    
            <TextView
                android:id="@+id/static_tolls"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignLeft="@+id/static_useCurrentLocation"
                android:layout_below="@+id/static_useCurrentLocation"
                android:textColor="#FFFFFF"
                android:textSize="20sp"
                android:paddingBottom="10dp"
                android:paddingTop="10dp"           
                android:text="@string/static_tolls" />
    
            <TextView
                android:id="@+id/static_highways"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@+id/static_tolls"
                android:layout_alignLeft="@+id/static_tolls"
                android:paddingBottom="10dp"
                android:text="@string/static_highways"
                android:textColor="#FFFFFF"
                android:textSize="20sp" />        
    
            <CheckBox
                android:id="@+id/tolls_checkbox"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignBaseline="@+id/static_tolls"
                android:layout_alignBottom="@+id/static_tolls"
                android:layout_alignParentRight="true"
                android:text="@string/checkbox" />
    
            <CheckBox
                android:id="@+id/highways_checkbox"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignBaseline="@+id/static_highways"
                android:layout_alignBottom="@+id/static_highways"
                android:layout_alignParentRight="true"
                android:text="@string/checkbox" />
    
            <CheckBox
                android:id="@+id/useLocation_checkbox"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignBaseline="@+id/static_useCurrentLocation"
                android:layout_alignBottom="@+id/static_useCurrentLocation"
                android:layout_alignParentRight="true"
                android:text="@string/checkbox" />      
    
        </RelativeLayout>
    
        <TextView
            android:id="@+id/static_destination"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/static_destination"
            android:textColor="#FFFFFF"
            android:textAppearance="?android:attr/textAppearanceLarge" />
    
        <AutoCompleteTextView
            android:id="@+id/aComplete_destination"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:ems="10"
            android:inputType="textNoSuggestions"
            android:text="@string/aComplete_destination" />
    
        <TextView
            android:id="@+id/static_language"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/static_language"
            android:textColor="#FFFFFF"
            android:textAppearance="?android:attr/textAppearanceLarge" />
    
        <RadioGroup
            android:id="@+id/radioGroup"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="horizontal" >
    
            <RadioButton
                android:id="@+id/radio_english"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:checked="true"
                android:textColor="#FFFFFF"
                android:layout_marginRight="20dp"
                android:text="@string/radio_english" />
    
            <RadioButton
                android:id="@+id/radio_portugues"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textColor="#FFFFFF"
                android:text="@string/radio_portugues" />
        </RadioGroup>
    
        <Button
            android:id="@+id/btn_getDirections"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="@string/btn_getDirections" />
    
    </LinearLayout>
    
    </ScrollView>