Ashley
Ashley

Reputation: 225

Scroll View - Need more screen space in android studio

I am trying to create a small unit converter app and need more screen space. After viewing previous questions I tried to switch my layout to a linear view and add a scroll view, but I still cannot add any additional elements to the page. Everything contained within the linear view is still set to the same size as the screen even though the window is scrolling.

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="fill_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".TestActivity"
android:id="@+id/scrollView"
android:fillViewport="false">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<EditText
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/temperatureEditText"
    android:hint="Enter Temperature"
    android:layout_below="@+id/temperatureTextView"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true" />

<RadioGroup
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/radioGroup"
    android:layout_below="@+id/temperatureEditText"
    android:layout_alignParentRight="true"
    android:layout_alignParentEnd="true">

    <RadioButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="From Celsius to Farenheight"
        android:id="@+id/toFarenheightRadioButton"
        android:checked="true" />

    <RadioButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="From Farenheight to Celsius"
        android:id="@+id/toCelsiusRadioButton"
        android:checked="false"
        android:visibility="visible" />
</RadioGroup>

<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Convert"
    android:id="@+id/convertButton"
    android:onClick="convert"
    android:layout_below="@+id/radioGroup"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true" />

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textAppearance="?android:attr/textAppearanceMedium"
    android:text="Temperature Conversion"
    android:id="@+id/temperatureTextView"
    android:layout_alignParentTop="true"
    android:layout_alignRight="@+id/sqFoottextView"
    android:layout_alignEnd="@+id/sqFoottextView" />

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textAppearance="?android:attr/textAppearanceMedium"
    android:text="Area Conversion"
    android:id="@+id/sqFoottextView"
    android:layout_below="@+id/convertButton"
    android:layout_alignRight="@+id/areaEditText"
    android:layout_alignEnd="@+id/areaEditText"
    android:layout_gravity="right" />

<EditText
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:inputType="number"
    android:ems="10"
    android:id="@+id/areaEditText"
    android:hint="Enter area"
    android:layout_below="@+id/sqFoottextView"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true" />

<RadioGroup
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@+id/areaEditText"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:id="@+id/areaRadioGroup">

    <RadioButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Sq. ft to Sq. meters"
        android:id="@+id/toSqMetersRadioButton"
        android:checked="true" />

    <RadioButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Sq. meters to Sq. feet"
        android:id="@+id/toSqFeetRadioButton"
        android:checked="false" />
</RadioGroup>

<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Convert"
    android:id="@+id/areaButton"
    android:onClick="areaConvert"
    android:layout_below="@+id/areaRadioGroup"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:nestedScrollingEnabled="true" />

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textAppearance="?android:attr/textAppearanceMedium"
    android:text="Length Conversions"
    android:id="@+id/lengthTextView"
    android:layout_below="@+id/areaButton"
    android:layout_alignRight="@+id/areaRadioGroup"
    android:layout_alignEnd="@+id/areaRadioGroup" />

<EditText
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:inputType="number"
    android:ems="10"
    android:id="@+id/lengthEditText"
    android:layout_below="@+id/lengthTextView"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:text="Enter Feet to convert" />

<RadioGroup
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_below="@+id/lengthEditText"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:id="@+id/lengthRadioGroup">

    <RadioButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Feet to Miles"
        android:id="@+id/toMilesRadioButton"
        android:checked="true" />
</RadioGroup>

<RadioButton
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Feet to Yards"
    android:id="@+id/toYardsRadioButton"
    android:layout_below="@+id/lengthRadioGroup"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:checked="false" />
</LinearLayout>

</ScrollView>

How to I increase the length of the screen? I tried to set the Linear view length to fill parent and that did not work either.

Upvotes: 9

Views: 666

Answers (2)

hiimcg
hiimcg

Reputation: 121

Changing android:orientation="horizontal" in the `LinearLayout' will allow it's contents to fill the parent properly

Upvotes: 1

kaherna8
kaherna8

Reputation: 161

You have to change your orientation to horizontal

Upvotes: 5

Related Questions