0

I have been trying to develop a form in android studio, and I am quite new to xml so not sure what I am doing wrong. Hopefully you can see from below, the preview shows as the boxes taking up basically the full page, however when I render it in a phone it only takes up half the page. Xml code is also below - any ideas would be greatly appreciated? Thanks

XML preview:

XML preview

Rendered view:

Android View

XML Code:

     <?xml version="1.0" encoding="utf-8"?>
 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/RelativeLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical"
android:theme="@style/AppTheme">

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_margin="@dimen/activity_horizontal_margin"
    android:orientation="vertical">


    <EditText
        android:id="@+id/editText10"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="50dp"
        android:background="@android:drawable/editbox_background_normal"
        android:ems="10"
        android:hint="Name"
        android:inputType="textPersonName" />


    <EditText
        android:id="@+id/editText7"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@android:drawable/editbox_background_normal"
        android:ems="10"
        android:hint="Date"
        android:inputType="date" />


    <EditText
        android:id="@+id/editText8"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@android:drawable/editbox_background_normal"
        android:ems="10"
        android:hint="Time"
        android:inputType="time" />


    <EditText
        android:id="@+id/editText9"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"

        android:background="@android:drawable/editbox_background_normal"
        android:ems="10"
        android:hint="Location"
        android:inputType="textPersonName" />


    <EditText
        android:id="@+id/editText11"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"

        android:layout_weight="1"
        android:background="@android:drawable/editbox_background_normal"
        android:ems="10"
        android:hint="Tester Notes"
        android:inputType="textMultiLine" />


    <CheckBox
        android:id="@+id/checkBox3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"

        android:layout_weight="1"
        android:text="Show Notes at appointment" />


    <CheckBox
        android:id="@+id/checkBox2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"

        android:text="Missed Appointment" />


    <LinearLayout
        android:id="@+id/Buttons"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:weightSum="2">

        <Button
            android:id="@+id/button3"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Save Notes" />

        <Button
            android:id="@+id/button2"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Send Email" />
    </LinearLayout>

    </LinearLayout>
</RelativeLayout>
user3095083
  • 145
  • 9

2 Answers2

0
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/ScrollView01"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:scrollbars="vertical">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">

        <LinearLayout
            android:id="@+id/Name"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal">

            <EditText
                android:id="@+id/editText10"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginStart="20dp"
                android:layout_marginTop="60dp"
                android:ems="10"
                android:hint="Name"
                android:inputType="textPersonName" />

        </LinearLayout>

        <LinearLayout
            android:id="@+id/Date"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal">

            <EditText
                android:id="@+id/editText7"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginStart="20dp"
                android:ems="10"
                android:hint="Date"
                android:inputType="date" />

        </LinearLayout>

        <LinearLayout
            android:id="@+id/Time"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal">

            <EditText
                android:id="@+id/editText8"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginStart="20dp"
                android:ems="10"
                android:hint="Time"
                android:inputType="time" />

        </LinearLayout>

        <LinearLayout
            android:id="@+id/location"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal">

            <EditText
                android:id="@+id/editText9"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginStart="20dp"
                android:ems="10"
                android:hint="Location"
                android:inputType="textPersonName" />

        </LinearLayout>

        <LinearLayout
            android:id="@+id/testernotes"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal">

            <EditText
                android:id="@+id/editText11"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginStart="20dp"
                android:layout_weight="1"
                android:ems="10"
                android:hint="Tester Notes"
                android:inputType="textMultiLine" />

        </LinearLayout>

        <LinearLayout
            android:id="@+id/checkbox"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal">

            <CheckBox
                android:id="@+id/checkBox3"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginStart="20dp"
                android:layout_weight="1"
                android:text="CheckBox" />
        </LinearLayout>

        <LinearLayout
            android:id="@+id/checkBox2"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal">

            <CheckBox
                android:id="@+id/checkBox2"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginStart="20dp"
                android:text="CheckBox" />
        </LinearLayout>

        <LinearLayout
            android:id="@+id/Buttons"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:weightSum="2"
            android:orientation="horizontal">

            <Button
                android:id="@+id/button3"
                android:text="button"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_marginStart="20dp"
                android:layout_weight="1" />

            <Button
                android:id="@+id/button2"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="Send Email" />
        </LinearLayout>

    </LinearLayout>
</ScrollView>

please try this xml

layout_weight and its usages was wrong in your xml ,while using layout_weight you have use android:layout_width = "0dp" as per the orientation,

for more info refer

[https://developer.android.com/guide/topics/ui/layout/linear.html][1]

https://blog.stylingandroid.com/layout-weights-part-1/

What does android:layout_weight mean?

much easier implementation

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/ScrollView01"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:scrollbars="vertical">

    <LinearLayout
        android:layout_margin="@dimen/activity_horizontal_margin"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">


            <EditText
                android:id="@+id/editText10"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="16dp"
                android:ems="10"
                android:hint="Name"
                android:inputType="textPersonName" />


            <EditText
                android:id="@+id/editText7"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:ems="10"
                android:hint="Date"
                android:inputType="date" />


            <EditText
                android:id="@+id/editText8"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:ems="10"
                android:hint="Time"
                android:inputType="time" />



            <EditText
                android:id="@+id/editText9"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"

                android:ems="10"
                android:hint="Location"
                android:inputType="textPersonName" />


            <EditText
                android:id="@+id/editText11"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"

                android:layout_weight="1"
                android:ems="10"
                android:hint="Tester Notes"
                android:inputType="textMultiLine" />



            <CheckBox
                android:id="@+id/checkBox3"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"

                android:layout_weight="1"
                android:text="CheckBox" />


            <CheckBox
                android:id="@+id/checkBox2"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"

                android:text="CheckBox" />



        <LinearLayout
            android:id="@+id/Buttons"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:weightSum="2"
            android:orientation="horizontal">

            <Button
                android:id="@+id/button3"
                android:text="button"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1" />

            <Button
                android:id="@+id/button2"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="Send Email" />
        </LinearLayout>

    </LinearLayout>
</ScrollView>
Basil jose
  • 774
  • 3
  • 11
  • still the same, I do think I need to move towards a relative layout but this seems to mess it all up even more... any ideas? – user3095083 Dec 21 '17 at 09:24
  • you have been using many linear layouts ,you can easily make this layout with two linear layouts by orietation, – Basil jose Dec 21 '17 at 09:28
  • @user3095083 updated my answer you can easily understand its ,if not let me know – Basil jose Dec 21 '17 at 09:34
  • @Basiljose Thanks, much prefer the simplified view so thanks for that! but the issue still persists of only rendering on one half of the page, I have implemented a side bar using the hamburger icon I think this could be causing the issue, have you ever seen anything like that before? Also I have now moved from a scrollview to a relative layout thanks to your simplified view which I needed so thank you!! Just to get this issue fixed now! – user3095083 Dec 21 '17 at 10:18
0

MATCH_PARENT means that the view wants to be as big as its parent, minus the parent's padding, if any.

Replace this:

android:layout_width="wrap_content"
android:layout_height="wrap_content"

With:

android:layout_width="match_parent"
android:layout_height="wrap_content"

into your LinearLayout.

MFaouzi
  • 1
  • 1