Android 为scrollview指定高度,而不使用dp中的大小

Android 为scrollview指定高度,而不使用dp中的大小,android,android-layout,uiscrollview,Android,Android Layout,Uiscrollview,我必须在设计布局时确保dp中没有硬编码值,所以我尝试使用权重为视图提供高度。我尝试在手机和平板电脑中使用相同的UI 但是,滚动视图不允许布局。我已将高度设置为滚动视图。我不想这样做 如何设置滚动视图或主视图的高度 在dp中使用重量/无硬编码的it中的集装箱布局 XML <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://s

我必须在设计布局时确保dp中没有硬编码值,所以我尝试使用权重为视图提供高度。我尝试在手机和平板电脑中使用相同的UI

但是,滚动视图不允许布局。我已将高度设置为滚动视图。我不想这样做

如何设置滚动视图或主视图的高度 在dp中使用重量/无硬编码的it中的集装箱布局

XML

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                xmlns:tools="http://schemas.android.com/tools"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical">


    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="120dp"//WANT TO AVOID HARD CODING
        android:layout_above="@+id/btn_signup"
        android:fadeScrollbars="false"
        android:scrollbarAlwaysDrawVerticalTrack="true"
        >

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="match_parent"

            android:orientation="vertical"
            android:paddingLeft="20dp"
            android:paddingRight="20dp"
            >

            <android.support.design.widget.TextInputLayout
                android:id="@+id/input_layout_name"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

                <EditText
                    android:id="@+id/roomno_et"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:hint="ROOM NO"
                    android:inputType="number"
                    android:singleLine="true"/>
            </android.support.design.widget.TextInputLayout>


            <android.support.design.widget.TextInputLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

                <EditText
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:hint="FIRST NAME"
                    android:inputType="text"
                    android:singleLine="true"/>
            </android.support.design.widget.TextInputLayout>

            <android.support.design.widget.TextInputLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

                <EditText
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:hint="LAST NAME"
                    android:inputType="text"
                    android:singleLine="true"/>
            </android.support.design.widget.TextInputLayout>
        </LinearLayout>

    </ScrollView>

    <Button
        android:id="@+id/btn_signup"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_marginTop="20dp"
        android:background="@color/colorPrimary"
        android:text="Checkin"
        android:textColor="@android:color/white"/>


</RelativeLayout>


您可以将
滚动视图
放在父
线性布局中
并为其分配权重

大概是这样的:

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_weight = "1">

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_above="@+id/btn_signup"
    android:fadeScrollbars="false"
    android:scrollbarAlwaysDrawVerticalTrack="true">

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:paddingLeft="20dp"
        android:paddingRight="20dp">

        <android.support.design.widget.TextInputLayout
            android:id="@+id/input_layout_name"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <EditText
                android:id="@+id/roomno_et"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:hint="ROOM NO"
                android:inputType="number"
                android:singleLine="true"/>
        </android.support.design.widget.TextInputLayout>


        <android.support.design.widget.TextInputLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <EditText
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:hint="FIRST NAME"
                android:inputType="text"
                android:singleLine="true"/>
        </android.support.design.widget.TextInputLayout>

        <android.support.design.widget.TextInputLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <EditText
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:hint="LAST NAME"
                android:inputType="text"
                android:singleLine="true"/>
        </android.support.design.widget.TextInputLayout>
    </LinearLayout>
</ScrollView>
</LinearLayout>

<Button
    android:id="@+id/btn_signup"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_marginTop="20dp"
    android:background="@color/colorPrimary"
    android:text="Checkin"
    android:textColor="@android:color/white"/>

但您的代码仍然有用于scrollview的android:layout\u height=“120dp”