带有 ScrollView 和 ListView 的 CoordinatorLayout 上的额外空白

Bal*_*era 5 android android-scrollview android-studio android-coordinatorlayout nestedscrollview

我已经使用 Android Studio 模板创建了一个 Scrolling Activity,这创建了一个 activity.xml 和一个 content.xml,它包含在具有 NestedScrollView 的 activity.xml 中,我在其中添加了来自适配器的 ListView 提要,起初它只显示一个项目,所以我以编程方式将它的大小设置为固定值,以便它实际上显示所有项目,我能够毫无问题地做到这一点,并且 NestedScrollView 毫无问题地包装了 ListView,但是有通过向所有元素添加背景颜色,我意识到 NestedScrollView 下方的空白区域来自 CoordinatorLayout,CoordinatorLayout 是活动中的主要标签。xml,但我无法弄清楚如何删除这个空白空间,因为如果我在 CoordinatorLayout 上使用 wrap_content ,它实际上会出于某种原因将我的内容修剪到屏幕的一半。

其他值得一提的是,如果我水平旋转手机,这个空白空间不会显示,只会出现在垂直位置。还,

有谁知道这可能是什么原因造成的?没什么大不了的,我什至可能会像这样离开它,但这对我来说很烦人,我无法弄清楚发生了什么。

这是我的activity.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    android:background="#00ff00" //Green
    tools:context=".VenueActivity">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/app_bar"
        android:layout_width="match_parent"
        android:layout_height="@dimen/app_bar_height"
        android:fitsSystemWindows="true"
        android:theme="@style/AppTheme.AppBarOverlay">

        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/toolbar_layout"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fitsSystemWindows="true"
            app:contentScrim="?attr/colorPrimary"
            app:layout_scrollFlags="scroll|exitUntilCollapsed">
                <ImageView
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:src="@drawable/frog"
                    android:scaleType="centerCrop"
                    />

            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                app:layout_collapseMode="pin"
                app:popupTheme="@style/AppTheme.PopupOverlay" />

        </android.support.design.widget.CollapsingToolbarLayout>
    </android.support.design.widget.AppBarLayout>

    <include layout="@layout/content_venue"/>

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="@dimen/fab_margin"
        android:src="@drawable/ic_favorite_white_24dp"
        app:layout_anchor="@id/app_bar"
        app:layout_anchorGravity="bottom|end" />

</android.support.design.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud)

这是我的 content.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:context=".VenueActivity"
    android:background="#ff0000" //Blue
    tools:showIn="@layout/activity_venue">


    <LinearLayout
        android:id="@+id/venueList"
        android:background="#ffff00" //Yellow
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <SearchView
            android:layout_width="match_parent"
            android:layout_height="55dp"
            android:id="@+id/searchView"
            android:queryHint="Search venues">

        </SearchView>

        <ListView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:id="@+id/songList" />

    </LinearLayout>


</android.support.v4.widget.NestedScrollView>
Run Code Online (Sandbox Code Playgroud)

最后我的java文件:

package com.example.android.myApplication;

import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

public class VenueActivity extends AppCompatActivity {

    //Set up my own database manually
    String[] db_ids = {"12345", "12345", "12345", "12345", "12345", "12345"};
    String[] db_songs = {"Item 1", "Item 2", "Item 3", "Item 4", "Item 5", "Item 6"};
    int[] db_thumbs = {R.drawable.ic_place_white_24dp, R.drawable.ic_place_white_24dp,
            R.drawable.ic_place_white_24dp, R.drawable.ic_place_white_24dp,
            R.drawable.ic_place_white_24dp, R.drawable.ic_place_white_24dp};

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_venue);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);

        Toast.makeText(VenueActivity.this, getIntent().getStringExtra("venue") + " was choosen", Toast.LENGTH_SHORT).show();
        FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
        fab.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Snackbar.make(view, "Venue has been added to your favourites", Snackbar.LENGTH_LONG)
                        .setAction("Action", null).show();
            }
        });

        /**
         *  LISTVIEW TO DISPLAY DIFFRENT VENUES
         */

        ListView lv = (ListView) findViewById(R.id.songList);
        lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                TextView selectedSong = (TextView) view.findViewById(R.id.songName);
                // TODO Third Fragment must be changed to the Venue Home or something different than this
                Toast.makeText(VenueActivity.this, selectedSong.getText(), Toast.LENGTH_SHORT).show();
                //     Intent intent = new Intent(view.getContext(),VenueActivity.class);
                //    intent.putExtra("venue", selectedVenue.getText());
                //     startActivity(intent);
            }
        });

        SongArrayAdapter ad = new SongArrayAdapter(db_ids, db_songs, db_thumbs, getApplicationContext());
        lv.setAdapter(ad);
        ListViewInScrollView.adapt(lv);

    }
}
Run Code Online (Sandbox Code Playgroud)

垂直视图一直滚动到底部

水平视图一直滚动到底部