Android XML相对布局走出屏幕

时间:2017-08-26 13:04:48

标签: android android-layout

在我的代码中,我使用了相对布局,但布局中的视图太多,因此相对布局不在屏幕之外。为了获得正确的观点,我应该使用什么? 这里ScrollView没有解决问题。

<?xml version="1.0" encoding="utf-8"?>


<RelativeLayout
    android:id="@+id/suitMeasurementRelativeLayout"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#ffffff"
    >



  <ScrollView
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:fillViewport="true"
      >

      <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        >

    <TextView
        android:layout_width="200dp"
        android:layout_height="35dp"
        android:text="Kameez(Top)"
        android:textColor="@color/boutiqueMaroon"
        android:layout_marginTop="10dp"
        android:layout_marginLeft="20dp"
        android:layout_marginRight="20dp"
        android:textSize="25sp"
        />

          <ImageButton
              android:id="@+id/closePopupSuit"
              android:layout_width="40dp"
              android:layout_height="40dp"
              android:background="@drawable/close_icon"
              android:layout_alignParentRight="true"
              />

    <EditText
        android:id="@+id/kameezMeasurementBust"
        android:layout_width="150dp"
        android:layout_height="40dp"
        android:layout_marginTop="60dp"
        android:layout_marginLeft="20dp"
        android:textColor="@color/boutiqueMaroon"
        android:hint="Bust"
        android:background="@color/EditTextBackground"
        android:textColorHint="@color/boutiqueMaroon"
        android:layout_alignParentLeft="true"
        />

    <EditText
        android:id="@+id/kameezMeasurementWaist"
        android:layout_width="150dp"
        android:layout_height="40dp"
        android:layout_marginTop="60dp"
        android:layout_marginRight="20dp"
        android:textColor="@color/boutiqueMaroon"
        android:hint="Waist"
        android:textColorHint="@color/boutiqueMaroon"
        android:background="@color/EditTextBackground"
        android:layout_alignParentRight="true"
        />
    <EditText
        android:id="@+id/kameezMeasurementHip"
        android:layout_width="150dp"
        android:layout_height="40dp"
        android:layout_marginTop="110dp"
        android:layout_marginLeft="20dp"
        android:textColor="@color/boutiqueMaroon"
        android:background="@color/EditTextBackground"
        android:hint="Hip"
        android:textColorHint="@color/boutiqueMaroon"
        android:layout_alignParentLeft="true"
        />
    <EditText
        android:id="@+id/kameezMeasurementSL"
        android:layout_width="150dp"
        android:layout_height="40dp"
        android:layout_marginTop="110dp"
        android:layout_marginRight="20dp"
        android:textColor="@color/boutiqueMaroon"
        android:background="@color/EditTextBackground"
        android:hint="Sleeve Length"
        android:textColorHint="@color/boutiqueMaroon"
        android:layout_alignParentRight="true"
        />
    <EditText
        android:id="@+id/kameezMeasurementArmhold"
        android:layout_width="150dp"
        android:layout_height="40dp"
        android:layout_marginTop="160dp"
        android:layout_marginLeft="20dp"
        android:textColor="@color/boutiqueMaroon"
        android:hint="Arm Hold"
        android:background="@color/EditTextBackground"
        android:textColorHint="@color/boutiqueMaroon"
        android:layout_alignParentLeft="true"
        />
    <EditText
        android:id="@+id/kameezMeasurementEndOfSleeve"
        android:layout_width="150dp"
        android:layout_height="40dp"
        android:layout_marginTop="210dp"
        android:layout_marginLeft="20dp"
        android:textColor="@color/boutiqueMaroon"
        android:hint="End of Sleeve"
        android:background="@color/EditTextBackground"
        android:textColorHint="@color/boutiqueMaroon"
        android:layout_alignParentLeft="true"
        />
    <EditText
        android:id="@+id/kameezMeasurementTopLength"
        android:layout_width="150dp"
        android:layout_height="40dp"
        android:layout_marginTop="210dp"
        android:textColor="@color/boutiqueMaroon"
        android:layout_marginRight="20dp"
        android:hint="Top Length"
        android:textColorHint="@color/boutiqueMaroon"
        android:background="@color/EditTextBackground"
        android:layout_alignParentRight="true"
        />
    <EditText
        android:id="@+id/kameezMeasurementFrontNeckLength"
        android:layout_width="150dp"
        android:layout_height="40dp"
        android:layout_marginTop="260dp"
        android:layout_marginLeft="20dp"
        android:textColor="@color/boutiqueMaroon"
        android:hint="Front Neck Length"
        android:background="@color/EditTextBackground"
        android:textColorHint="@color/boutiqueMaroon"
        android:layout_alignParentLeft="true"
        />
    <EditText
        android:id="@+id/kameezMeasurementBackNeckLength"
        android:layout_width="150dp"
        android:layout_height="40dp"
        android:layout_marginTop="260dp"
        android:textColor="@color/boutiqueMaroon"
        android:layout_marginRight="20dp"
        android:hint="Back Neck length"
        android:textColorHint="@color/boutiqueMaroon"
        android:background="@color/EditTextBackground"
        android:layout_alignParentRight="true"
        />

    <View
        android:layout_width="match_parent"
        android:layout_height="0.5dp"
        android:background="@color/boutiqueMaroon"
        android:layout_marginTop="320dp"
        />

    <TextView
        android:layout_width="match_parent"
        android:layout_height="35dp"
        android:text="Salwar(Pant)"
        android:textColor="@color/boutiqueMaroon"
        android:layout_marginTop="330dp"
        android:layout_marginLeft="20dp"
        android:layout_marginRight="20dp"
        android:textSize="25sp"
        />

    <EditText
        android:id="@+id/salwarMeasurementWaist"
        android:layout_width="150dp"
        android:layout_height="40dp"
        android:layout_marginTop="380dp"
        android:layout_marginLeft="20dp"
        android:textColor="@color/boutiqueMaroon"
        android:hint="Waist"
        android:background="@color/EditTextBackground"
        android:textColorHint="@color/boutiqueMaroon"
        android:layout_alignParentLeft="true"
        />

    <EditText
        android:id="@+id/salwarMeasurementHips"
        android:layout_width="150dp"
        android:layout_height="40dp"
        android:layout_marginTop="380dp"
        android:layout_marginRight="20dp"
        android:textColor="@color/boutiqueMaroon"
        android:hint="Hips"
        android:textColorHint="@color/boutiqueMaroon"
        android:background="@color/EditTextBackground"
        android:layout_alignParentRight="true"
        />
    <EditText
        android:id="@+id/salwarMeasurementHemLength"
        android:layout_width="150dp"
        android:layout_height="40dp"
        android:layout_marginTop="430dp"
        android:layout_marginLeft="20dp"
        android:textColor="@color/boutiqueMaroon"
        android:background="@color/EditTextBackground"
        android:hint="Hem Length"
        android:textColorHint="@color/boutiqueMaroon"
        android:layout_alignParentLeft="true"
        />
    <EditText
        android:id="@+id/salwarMeasurementTL"
        android:layout_width="150dp"
        android:layout_height="40dp"
        android:layout_marginTop="430dp"
        android:layout_marginRight="20dp"
        android:textColor="@color/boutiqueMaroon"
        android:background="@color/EditTextBackground"
        android:hint="Total Length"
        android:textColorHint="@color/boutiqueMaroon"
        android:layout_alignParentRight="true"
        />
    <EditText
        android:id="@+id/salwarMeasurementWaistHipLength"
        android:layout_width="match_parent"
        android:layout_height="40dp"
        android:layout_marginTop="480dp"
        android:layout_marginLeft="20dp"
        android:layout_marginRight="20dp"
        android:textColor="@color/boutiqueMaroon"
        android:hint="Length between waist and hip"
        android:background="@color/EditTextBackground"
        android:textColorHint="@color/boutiqueMaroon"
        android:layout_alignParentLeft="true"
        />


    <Button
        android:layout_width="match_parent"
        android:layout_height="35dp"
        android:layout_marginLeft="20dp"
        android:layout_marginRight="20dp"
        android:layout_marginTop="550dp"
        android:background="@color/boutiqueMaroon"
        android:text="Submit"
        android:layout_marginBottom="50dp"
        />



    </RelativeLayout>

  </ScrollView>

</RelativeLayout>

Here is the image of output.The submit button is not fully visible and also the scrollview not working properly here

2 个答案:

答案 0 :(得分:0)

将您的按钮放在滚动视图之外。

  </ScrollView>

    <Button
        android:layout_width="match_parent"
        android:alignparent_bottom="true"
        android:layout_height="35dp"
        android:layout_marginLeft="20dp"
        android:layout_marginRight="20dp"
        android:layout_marginTop="50dp"
        android:background="@color/boutiqueMaroon"
        android:text="Submit"
        android:layout_marginBottom="50dp"
        />

</RelativeLayout>

并在按钮上方创建RelativeLayout(表单容器)。因此,您的表单将获得滚动,但按钮将显示在屏幕上。

答案 1 :(得分:0)

将所有对象放在ScrllView中,不带任何布局