Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/223.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
Android 将Listview和LinearLayout嵌套在LinearLayout中会产生ui问题_Android_Listview - Fatal编程技术网

Android 将Listview和LinearLayout嵌套在LinearLayout中会产生ui问题

Android 将Listview和LinearLayout嵌套在LinearLayout中会产生ui问题,android,listview,Android,Listview,我希望我的ui是可滚动的。我有一个线性布局,其中嵌套了ListView和另一个线性布局。下面是我的代码 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_pare

我希望我的ui是可滚动的。我有一个线性布局,其中嵌套了ListView和另一个线性布局。下面是我的代码

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">


    <ListView
        android:id="@+id/list"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_vertical"
        android:layout_weight="10"
        android:divider="@null"
        android:dividerHeight="0dp"
        android:paddingTop="10dp" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="10dp"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp"
        android:layout_marginTop="10dp"
        android:layout_weight="5"
        android:background="@drawable/border"
        android:orientation="vertical">

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="3dp"
            android:layout_marginTop="3dp"
            android:orientation="horizontal">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Vessal Name:" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Maize" />
        </LinearLayout>

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="3dp"
            android:orientation="horizontal">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="ETD: " />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="09 OCT 2014" />
        </LinearLayout>

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="3dp"
            android:orientation="horizontal">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="ETA: " />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="89.Oct 2034" />
        </LinearLayout>

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="3dp"
            android:orientation="horizontal">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Revised ETA" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="9 Oct 2014" />
        </LinearLayout>

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="horizontal">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Notes/ Remarks" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Nice delivery" />
        </LinearLayout>
    </LinearLayout>
</LinearLayout>


问题是最后出现的几个文本视图在ui中不可见。如何使其可见?

使用scrollview,您的问题将得到解决

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

            <!-- everything you already have -->

    </ScrollView>

根据

视图层次结构的布局容器,可通过 用户,允许其大于物理显示。滚动视图 是一个框架布局,意味着您应该在其中放置一个子项,其中包含 滚动整个内容;此子项本身可能是一个布局 具有复杂对象层次结构的管理器。经常生病的孩子 使用的是垂直方向的线性布局,表示 用户可以滚动浏览的顶级项目的垂直数组

您不应该将ScrollView与ListView一起使用,因为ListView 负责自己的垂直滚动。最重要的是,这样做 击败ListView中的所有重要优化以处理 对于大型列表,因为它有效地强制ListView显示 它的整个项目列表将填充由提供的无限容器 滚动视图

TextView类还负责自己的滚动,所以不会 需要滚动视图,但同时使用这两个视图可以 在更大的容器中实现文本视图的效果

您的
xml
如下

<ScrollView>
  <LinearLayout>
    <EditText/>
    <TextView/>
  </LinearLayout>
</ScrollView>


注意:
滚动视图中应该只有一个父布局

您可以将线性布局放在SCOLLVIEW中。切勿将ListView高度换行内容。您应该将线性布局放在单独的xml中的Listview下面,将其膨胀并执行
Listview.addFooterView(膨胀视图)
。它不允许我在其中滚动内容linearlayout@user1241241您是否使用scrollview作为父视图?是的,我尝试使用scrollview作为父视图,但问题仍然存在