Android Listview内部协调器布局如何使其可滚动?

Android Listview内部协调器布局如何使其可滚动?,android,listview,Android,Listview,我有listactivity.java,它的代码如下。注意它使用 活动\u main\u listapps1.xml和listview\u布局文件 setContentView(R.layout.activity_main_listapps1); String[] from = { "flag","label","cur" ,"right_flag"}; // Ids of views in listview_layout int[] to = { R.id.flag

我有listactivity.java,它的代码如下。注意它使用 活动\u main\u listapps1.xml和listview\u布局文件

    setContentView(R.layout.activity_main_listapps1);

String[] from = { "flag","label","cur" ,"right_flag"};

    // Ids of views in listview_layout
    int[] to = { R.id.flag,R.id.txt,R.id.cur,R.id.right_flag};

    // Instantiating an adapter to store each items
    // R.layout.listview_layout defines the layout of each item
    SimpleAdapter adapter = new SimpleAdapter(getBaseContext(), aList, R.layout.listview_layout, from, to);

    // Getting a reference to listview of layout file
    ListView listView = ( ListView ) findViewById(R.id.listview);

    // Setting the adapter to the listView
    listView.setAdapter(adapter);
其中activity_main_listapps1.xml为:

<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/drawer_design_support_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <android.support.design.widget.CoordinatorLayout
        android:id="@+id/rootLayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <android.support.design.widget.AppBarLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
            <android.support.design.widget.TabLayout
                android:id="@+id/tab_layout"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" />
            <ListView
                android:id="@+id/listview"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                />
        </android.support.design.widget.AppBarLayout>
    </android.support.design.widget.CoordinatorLayout>
</android.support.v4.widget.DrawerLayout>

listview_layout.xml是:

<?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="horizontal"
    >
    <ImageView
        android:id="@+id/flag"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:contentDescription="hello"
        android:paddingTop="10dp"
        android:paddingRight="10dp"
        android:paddingBottom="10dp"
        android:layout_weight="1" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:layout_weight="2">
        <TextView
            android:id="@+id/txt"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textSize="15dp"
            />

        <TextView
            android:id="@+id/cur"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textSize="10dp"
            />
    </LinearLayout>


    <ImageView
        android:id="@+id/right_flag"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:contentDescription="hello"
        android:paddingTop="10dp"
        android:paddingRight="10dp"
        android:paddingBottom="10dp"
        android:visibility="visible"
        android:layout_weight="1" />
</LinearLayout>


此代码不可滚动。我尝试添加android:layout\u height以匹配父视图。仍然缺少一些内容。

从appbar布局中删除listview,并将其写入appbarlayout外部,也将其写入坐标布局内的嵌套滚动视图中

<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/drawer_design_support_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.CoordinatorLayout
    android:id="@+id/rootLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <android.support.design.widget.TabLayout
            android:id="@+id/tab_layout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" />
        <ListView
            android:id="@+id/listview"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            />
    </android.support.design.widget.AppBarLayout>
            <android.support.v4.widget.NestedScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    android:fillViewport="true">
            <ListView
            android:id="@+id/listview"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
      <android.support.v4.widget.NestedScrollView/>
</android.support.design.widget.CoordinatorLayout>


从appbar布局中删除listview,并将其写入appbarlayout外部,也将其写入坐标布局内的嵌套滚动视图中

<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/drawer_design_support_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.CoordinatorLayout
    android:id="@+id/rootLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <android.support.design.widget.TabLayout
            android:id="@+id/tab_layout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" />
        <ListView
            android:id="@+id/listview"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            />
    </android.support.design.widget.AppBarLayout>
            <android.support.v4.widget.NestedScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    android:fillViewport="true">
            <ListView
            android:id="@+id/listview"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
      <android.support.v4.widget.NestedScrollView/>
</android.support.design.widget.CoordinatorLayout>


从appbar布局中删除您的listview,并将其写入appbarlayout外部,也将其写入坐标布局中的嵌套滚动视图中。然后将app:layout\u behavior=“@string/appbar\u scrolling\u view\u behavior”添加到您的listview谢谢,我将listview删除并放置在appbarlayout外部。现在它可以滚动了。。我将尝试另外两个关于滚动视图和布局的建议。行为主义者现在看起来很棒。我将listview移到appbarlayout之外,并添加了app:layout\u行为。它现在工作正常:)请移动此评论以进行答复。谢谢另外两个建议是针对kitkat的,因为kitkat及以下版本的滚动速度较慢,所以您应该在嵌套的滚动视图中使用它,但滚动的行为\u视图\u行为从appbar布局中删除listview,并将其写入appbarlayout之外,也将其写入坐标布局内的嵌套滚动视图中。然后将app:layout\u behavior=“@string/appbar\u scrolling\u view\u behavior”添加到您的listview谢谢,我将listview删除并放置在appbarlayout之外。现在它可以滚动了。。我将尝试另外两个关于滚动视图和布局的建议。行为主义者现在看起来很棒。我将listview移到appbarlayout之外,并添加了app:layout\u行为。它现在工作正常:)请移动此评论以进行答复。谢谢另外两个建议是针对kitkat的,因为在kitkat及以下版本中滚动速度较慢,所以你应该在嵌套的滚动视图中使用它,但是在滚动视图(甚至是嵌套的滚动视图)中使用滚动视图行为或列表视图的行为不是一个好主意。(一个可滚动视图位于另一个可滚动视图中)。另外,我测试了这样一个案例,我的ListView只显示了一个元素。在ScrollView(甚至NestedScrollView)中使用ListView不是一个好主意。(一个可滚动视图位于另一个可滚动视图中)。另外,我测试了这样一个案例,我的ListView只显示了一个元素。