单击ListView项时,CollapsingToolbarLayout会自动折叠

时间:2016-12-18 12:02:57

标签: android listview android-collapsingtoolbarlayout

我在NestedScrollView下有一个listView,我的活动也包含`CollapsingToolbarLayout。

每个都像scrollingonItemClick一样工作。但我的listView项目包含ImageView。如果单击imageView,将出现一个弹出窗口。 但是,当我点击图片时,CollapsingToolbarLayout正在崩溃。

我的代码是

ListView活动

<?xml version="1.0" encoding="utf-8"?>

<android.support.v7.widget.CardView
    android:id="@+id/cardViewSongList"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_margin="3dp"
    android:foreground="?android:attr/selectableItemBackground"
    card_view:cardCornerRadius="1dp"
    card_view:cardUseCompatPadding="true">

    <ListView
        android:id="@+id/songList"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_below="@+id/albumArtOnSongList"
        android:divider="@null"
        android:paddingLeft="8dp"
        android:paddingRight="8dp"
        android:scrollbars="none">

    </ListView>

</android.support.v7.widget.CardView>

CollapsingToolbarLayout

<?xml version="1.0" encoding="utf-8"?>

<android.support.design.widget.AppBarLayout
    android:id="@+id/app_bar"
    android:layout_width="match_parent"
    android:layout_height="240dp"
    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="240dp"
        android:fitsSystemWindows="true"
        android:background="@drawable/gramophone"
        app:contentScrim="?attr/colorPrimary"
        app:layout_scrollFlags="scroll|exitUntilCollapsed">


        <ImageView
            android:id="@+id/albumArtOnSongList"
            android:layout_width="match_parent"
            android:layout_height="240dp"
            android:scaleType="centerCrop"
            android:src="@drawable/album"
            android:transitionName="@string/albumInageTransition" />


        <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_songs_list" />

ListViewAdapter代码:(点击处理)

  holder.optionImage.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            PopupMenu popupMenu = new PopupMenu(context, v);
            popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
                @Override
                public boolean onMenuItemClick(MenuItem item) {
                    switch (item.getItemId()) {

                        case R.id.download:
                            Toast.makeText(context, "Download", Toast.LENGTH_SHORT).show();
                            return true;

                        case R.id.select:

                            selectionStarted = true;
                            holder.checkBox.setVisibility(View.VISIBLE);
                            selectedPosition.add(String.valueOf(position));
                            markedAlbumData.add(data.get(position));
                            notifyDataSetChanged();


                            Toast.makeText(context, "select Clicked", Toast.LENGTH_SHORT).show();
                            return true;

                        case R.id.play:
                            Toast.makeText(context, "play Clicked", Toast.LENGTH_SHORT).show();
                            return true;
                    }
                    return false;
                }
            });
            popupMenu.inflate(R.menu.pop_up_option_album);
            popupMenu.show();


        }
    });

如何停止此自动折叠? enter image description here

1 个答案:

答案 0 :(得分:1)

使用此代码

context.ChangeTracker.AutoDetectChangesEnabled = false;

不创建如下的弹出式菜单:

        PopupMenu popup = new PopupMenu(mContext, view, Gravity.RIGHT);