Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/366.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/multithreading/4.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 ListView无法在Android中自动增长_Java_Android Layout_Listview - Fatal编程技术网

Java ListView无法在Android中自动增长

Java ListView无法在Android中自动增长,java,android-layout,listview,Java,Android Layout,Listview,在填充ListView时,我遇到了两个问题。 1.我看不到第一个元素。 2.我只有在硬编码高度时才能看到我的列表。我如何避免这种情况 <?xml version="1.0" encoding="utf-8"?> <android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas

在填充ListView时,我遇到了两个问题。 1.我看不到第一个元素。 2.我只有在硬编码高度时才能看到我的列表。我如何避免这种情况

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView 
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"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:background="?attr/layout_background_color">

    <LinearLayout
        android:id="@+id/colors_container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:visibility="visible">

        <ListView
            android:id="@+id/colors_list"
            android:layout_width="match_parent"
            android:layout_height="3500dp" />

    </LinearLayout>

</android.support.v4.widget.NestedScrollView>


谢谢你给我的任何帮助。谢谢

发生这种情况是因为您将
列表视图
放在
嵌套滚动视图

ListView
可以是任何
布局
,但是如果你想把它放在
嵌套滚动视图
中,你必须做些什么。生活中没有什么是免费的

解决方案:

以编程方式计算高度

是解决您的问题的链接


使用
RecyclerView
而不是
ListView
,您将不需要进行上述黑客操作。

非常感谢您提供的提示!知道我为什么看不到列表中的第一个元素吗?我看到了除第一位以外的所有其他成员。