为什么我的应用只呈现页面的一半?

时间:2017-12-21 08:57:55

标签: android android-layout

我一直在尝试在android studio中开发一个表单,我对xml很新,所以不确定我做错了什么。希望您可以从下面看到,预览显示为基本上占据整页的框,但是当我在手机中呈现它时,它只占用了一半的页面。 Xml代码也在下面 - 任何想法将不胜感激?感谢

XML预览:

XML preview

渲染视图:

Android View

XML代码:

     <?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>

2 个答案:

答案 0 :(得分: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>

请试试这个xml

layout_weight及其在xml中的用法错误,而使用layout_weight则根据方向使用android:layout_width = "0dp"

了解更多信息,请参阅

[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?

更容易实施

<?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>

答案 1 :(得分:0)

MATCH_PARENT意味着视图要与其父级一样大,减去父级的填充(如果有的话)。

替换它:

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

使用:

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

进入LinearLayout

相关问题