特定RelativeLayout上的ScrollView

时间:2018-04-17 20:26:57

标签: android layout

我需要你对这个设计的帮助

enter image description here

正如您所看到的那样,最后一项是旋转器不适合布局。文本视图中的布局是相对布局。而灰色背景是LinearLayout。所以我希望只能滚动RelativeLayout(白色背景的那个)而不是所有的LinearLayout。 有没有办法做到这一点?我真的很感激你的回答。

谢谢

我的代码

<android.support.design.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/gray">

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

        <RelativeLayout
            android:id="@+id/viewB"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_marginBottom="65dp"
            android:layout_marginEnd="15dp"
            android:layout_marginStart="15dp"
            android:layout_marginTop="45dp"
            android:layout_weight="0.4"
            android:background="@drawable/registro_background"
            android:orientation="horizontal">



            <EditText
                android:id="@+id/ci"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_alignParentTop="true"
                android:layout_centerHorizontal="true"
                android:layout_marginTop="61dp"
                android:layout_marginStart="15dp"
                android:layout_marginEnd="15dp"
                android:background="@drawable/edit_corner"
                android:gravity="center|left"
                android:hint="CI"
                android:padding="10dp"
                android:textColor="@color/orange"
                android:textColorHint="@color/naranja_lago"
                android:textSize="20sp"
                android:drawableLeft="@drawable/cliente_user"/>

            <EditText
                android:id="@+id/nombre"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_alignStart="@+id/ci"
                android:layout_below="@+id/ci"
                android:layout_marginTop="12dp"
                android:layout_marginEnd="15dp"
                android:background="@drawable/edit_corner"
                android:drawableLeft="@drawable/cliente_user"
                android:gravity="center|left"
                android:hint="Nombre y Apellido"
                android:padding="10dp"
                android:textColor="@color/orange"
                android:textColorHint="@color/naranja_lago"
                android:textSize="20sp" />

            <EditText
                android:id="@+id/correo"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_alignParentStart="true"
                android:layout_below="@+id/nombre"
                android:layout_marginTop="15dp"
                android:layout_marginStart="15dp"
                android:layout_marginEnd="15dp"
                android:background="@drawable/edit_corner"
                android:gravity="center|left"
                android:hint="Email"
                android:padding="10dp"
                android:textColor="@color/orange"
                android:textColorHint="@color/naranja_lago"
                android:textSize="20sp"
                android:inputType="textEmailAddress"
                android:drawableLeft="@drawable/cliente_email"/>

            <EditText
                android:id="@+id/telefono"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_alignParentStart="true"
                android:layout_below="@+id/correo"
                android:layout_marginTop="15dp"
                android:layout_marginStart="15dp"
                android:layout_marginEnd="15dp"
                android:background="@drawable/edit_corner"
                android:gravity="center|left"
                android:hint="Teléfono"
                android:padding="10dp"
                android:textColor="@color/orange"
                android:textColorHint="@color/naranja_lago"
                android:textSize="20sp"
                android:inputType="phone"
                android:drawableLeft="@drawable/cliente_phone"/>

            <Spinner
                android:id="@+id/lugar"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_alignParentStart="true"
                android:layout_below="@+id/telefono"
                android:layout_marginTop="15dp"
                android:layout_marginStart="15dp"
                android:layout_marginEnd="15dp"
                android:background="@drawable/edit_corner"
                android:gravity="center|left"
                android:hint="Lugar"
                android:padding="10dp"
                android:textColor="#6d6e71"
                android:textColorHint="#f7941e"
                android:textSize="20sp" />



        </RelativeLayout>


        <Button
            android:id="@+id/registrar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@drawable/button_corner"
            android:layout_marginEnd="15dp"
            android:layout_marginStart="15dp"
            android:layout_marginBottom="15dp"
            android:textColor="@color/white"
            android:text="REGISTRAR"/>




    </LinearLayout>


    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/registro_cliente"
        app:layout_anchor="@id/viewB"
        app:layout_anchorGravity="top|center|center_horizontal" />


</android.support.design.widget.CoordinatorLayout>

1 个答案:

答案 0 :(得分:0)

我测试了类似你的类似设置来测试RelativeLayout中视图的滚动,它对我有用。你能否检查它是否适合你:

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

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

        <ImageView
            android:id="@+id/imageView"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:srcCompat="@drawable/ic_launcher_background" />

        <ScrollView
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
        <RelativeLayout
            android:gravity="center"
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <Button
                android:id="@+id/button1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Button"
                android:layout_marginTop="50dp"
                android:gravity="center"
                tools:layout_editor_absoluteX="16dp"
                tools:layout_editor_absoluteY="26dp" />

            <Button
                android:id="@+id/button2"
                android:layout_below="@id/button1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Button"
                android:layout_marginTop="50dp"
                android:gravity="center"
                tools:layout_editor_absoluteX="16dp"
                tools:layout_editor_absoluteY="26dp" />

            <Button
                android:id="@+id/button3"
                android:layout_below="@id/button2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Button"
                android:layout_marginTop="50dp"
                android:gravity="center"
                tools:layout_editor_absoluteX="16dp"
                tools:layout_editor_absoluteY="26dp" />

            <Button
                android:id="@+id/button4"
                android:layout_below="@id/button3"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Button"
                android:layout_marginTop="50dp"
                android:gravity="center"
                tools:layout_editor_absoluteX="16dp"
                tools:layout_editor_absoluteY="26dp" />

            <Button
                android:id="@+id/button5"
                android:layout_below="@id/button4"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Button"
                android:layout_marginTop="50dp"
                android:gravity="center"
                tools:layout_editor_absoluteX="16dp"
                tools:layout_editor_absoluteY="26dp" />

        </RelativeLayout>
        </ScrollView>
    </LinearLayout>

</android.support.constraint.ConstraintLayout>