Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/181.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 将视图的最小高度设置为其父视图的高度_Java_Android - Fatal编程技术网

Java 将视图的最小高度设置为其父视图的高度

Java 将视图的最小高度设置为其父视图的高度,java,android,Java,Android,在滚动视图中,我有一个线性布局。LinearLayout可以任意高,但我希望其最小高度至少与其父级(滚动视图)一样高 这是行不通的。对于最小高度,它将不接受的“匹配父项”。那么我该如何处理这个问题呢?所以当线性布局中的内容没有填满ScrollView允许的空间时,您只想避免浪费房地产?将LinearLayout height设置为: android:layout_height="match_parent" 您可以在ScrollView上设置相同的属性,使其也适合自己的父对象,但不是严格必需

在滚动视图中,我有一个线性布局。LinearLayout可以任意高,但我希望其最小高度至少与其父级(滚动视图)一样高



这是行不通的。对于
最小高度
,它将不接受
的“匹配父项”
。那么我该如何处理这个问题呢?

所以当线性布局中的内容没有填满ScrollView允许的空间时,您只想避免浪费房地产?将LinearLayout height设置为:

android:layout_height="match_parent"

您可以在ScrollView上设置相同的属性,使其也适合自己的父对象,但不是严格必需的。

您可以在xml文件中使用ScrollView的
android:fillViewport=“true”
属性,如下所示:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fillViewport="true">

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

        <!--Rest of the children-->
    </LinearLayout>

</ScrollView>


我会使用Java中的
设置最小高度(int)
这有帮助吗@德里克朕會功夫 这应该行得通。是否确定线性布局中的元素占用可用空间?i、 e.重量设定你这是什么意思?你能展示一个示例代码吗?Derek-如果你包括完整的布局XML和你得到的屏幕截图,并解释它的错误,我们应该能够提供帮助。这使ScrollView很高,但不是内部元素(LinearLayout)。
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fillViewport="true">

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

        <!--Rest of the children-->
    </LinearLayout>

</ScrollView>