Android:ListView在Coordinator布局和CollasingToolBarLayout中未正确滚动

Android:ListView在Coordinator布局和CollasingToolBarLayout中未正确滚动,android,listview,xamarin,android-coordinatorlayout,android-collapsingtoolbarlayout,Android,Listview,Xamarin,Android Coordinatorlayout,Android Collapsingtoolbarlayout,大家早上好 我的应用程序中存在滚动问题。我有一个协调器布局和一个列表视图。当我在listview中滚动时,我希望顶部布局正在折叠。 我搜索发现,如果没有NestedScrollView,这是不可能的,所以我添加了一个 问题是当我滚动时,只有协调器布局在滚动 例如,当我向下滚动时,listview如下所示: 我还尝试将我的Listview的layout\u height设置为match\u parent,但它没有改变任何东西 这是我的密码: main.xml <android.suppor

大家早上好

我的应用程序中存在滚动问题。我有一个协调器布局和一个列表视图。当我在listview中滚动时,我希望顶部布局正在折叠。 我搜索发现,如果没有NestedScrollView,这是不可能的,所以我添加了一个

问题是当我滚动时,只有协调器布局在滚动

例如,当我向下滚动时,listview如下所示:

我还尝试将我的
Listview
layout\u height
设置为
match\u parent
,但它没有改变任何东西

这是我的密码:

main.xml

<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/main_content"
    android:fitsSystemWindows="true"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <android.support.design.widget.AppBarLayout
        android:id="@+id/appbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/ActionBarNoShadowLight"
        android:fitsSystemWindows="true"
        app:elevation="0dp">
        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/collapsing_toolbar"
            android:layout_height="match_parent"
            android:layout_width="match_parent"
            app:layout_scrollFlags="scroll|exitUntilCollapsed"
            app:contentScrim="?attr/colorPrimary"
            app:expandedTitleMarginStart="48dp"
            app:expandedTitleMarginEnd="64dp"
            android:fitsSystemWindows="true">
            <ImageView
                android:id="@+id/mainImage"
                android:layout_width="175dp"
                android:layout_height="175dp"
                android:layout_marginTop="50dp"
                android:layout_alignParentTop="true"
                android:layout_centerHorizontal="true"
                android:scaleType="fitCenter"
                app:srcCompat="@drawable/ic_document"
                android:fitsSystemWindows="true"
                app:layout_collapseMode="parallax" />
            <android.support.v7.widget.Toolbar
                android:id="@+id/edit_toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                android:background="@color/BackgroundWhite"
                app:layout_collapseMode="pin"
                app:layout_scrollFlags="scroll|enterAlways"
                app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
        </android.support.design.widget.CollapsingToolbarLayout>
    </android.support.design.widget.AppBarLayout>
    <android.support.v4.widget.NestedScrollView
        android:id="@+id/scroll"
        android:layout_width="match_parent"
        android:layout_height="fill_parent"
        android:clipToPadding="false"
        android:scrollbars="none"
        android:fillViewport="true"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">
        <FrameLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content" >
            <ListView
                android:id="@+id/lstTask"
                android:layout_height="match_parent"
                android:layout_width="fill_parent"
                android:nestedScrollingEnabled="true"
                android:layout_marginLeft="8dp"
                android:layout_marginRight="8dp"
                android:divider="@null"
                />
            <ImageView
                android:id="@+id/empty"
                android:layout_height="200dp"
                android:layout_width="200dp"
                android:layout_marginTop="50dp"
                android:scaleType="fitCenter"
                android:gravity="center"
                android:layout_alignParentTop="true"
                android:layout_centerHorizontal="true"
                app:srcCompat="@drawable/bg_notasks" />
        </FrameLayout>
    </android.support.v4.widget.NestedScrollView>
    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fabAdd"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="end|bottom"
        android:layout_margin="@dimen/fab_margin"
        android:src="@drawable/ic_plus" />
</android.support.design.widget.CoordinatorLayout>

非常感谢你以后的帮助,
Clément.

创建一个
非CrollListView
类,如下所示

public class NonScrollListView extends ListView{

public NonScrollListView(Context context) {
    super(context);
}

public NonScrollListView(Context context, AttributeSet attrs) {
    super(context, attrs);
}

public NonScrollListView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
}

@Override
public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    int heightMeasureSpec_custom = MeasureSpec.makeMeasureSpec(
            Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST);
    super.onMeasure(widthMeasureSpec, heightMeasureSpec_custom);
    ViewGroup.LayoutParams params = getLayoutParams();
    params.height = getMeasuredHeight();
}
}
并在
xml
中添加布局行为

<android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/ll_pro_profile_reviews"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white"
android:orientation="vertical"
app:layout_behavior="@string/appbar_scrolling_view_behavior">

<com.vanitee.services.home.customer.shops.detail.reviews.NonScrollExpandableListView
    android:id="@+id/rcv_pro_profile_reviews"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/spacing_8"/>

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

创建一个
非CrollListView
类,如下所示

public class NonScrollListView extends ListView{

public NonScrollListView(Context context) {
    super(context);
}

public NonScrollListView(Context context, AttributeSet attrs) {
    super(context, attrs);
}

public NonScrollListView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
}

@Override
public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    int heightMeasureSpec_custom = MeasureSpec.makeMeasureSpec(
            Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST);
    super.onMeasure(widthMeasureSpec, heightMeasureSpec_custom);
    ViewGroup.LayoutParams params = getLayoutParams();
    params.height = getMeasuredHeight();
}
}
并在
xml
中添加布局行为

<android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/ll_pro_profile_reviews"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white"
android:orientation="vertical"
app:layout_behavior="@string/appbar_scrolling_view_behavior">

<com.vanitee.services.home.customer.shops.detail.reviews.NonScrollExpandableListView
    android:id="@+id/rcv_pro_profile_reviews"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/spacing_8"/>

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

只需帮助您将Ayush Khare的代码转换为C#,如果这对您有帮助,您可以标记 @阿尤什·哈雷的回答

public class NonScrollListView : ListView
{
    public NonScrollListView(Context context) : base(context)
    {
    }

    public NonScrollListView(Context context, IAttributeSet attrs) : base(context, attrs)
    {
    }

    public NonScrollListView(Context context, IAttributeSet attrs, int defStyle) : base(context, attrs, defStyle)
    {
    }

    protected override void OnMeasure(int widthMeasureSpec, int heightMeasureSpec)
    {
        int heightMeasureSpec_custom = MeasureSpec.MakeMeasureSpec(int.MaxValue >> 2, MeasureSpecMode.AtMost);
        base.OnMeasure(widthMeasureSpec, heightMeasureSpec);

        ViewGroup.LayoutParams params2 = LayoutParameters;
        params2.Height = MeasuredHeight;
    }
}
禁用嵌套滚动:

if (Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.Lollipop)
{
    listView.NestedScrollingEnabled = false;
}
else
{
    ViewCompat.SetNestedScrollingEnabled(listView, false);
}

只需帮助您将Ayush Khare的代码转换为C#,如果这对您有帮助,您可以标记 @阿尤什·哈雷的回答

public class NonScrollListView : ListView
{
    public NonScrollListView(Context context) : base(context)
    {
    }

    public NonScrollListView(Context context, IAttributeSet attrs) : base(context, attrs)
    {
    }

    public NonScrollListView(Context context, IAttributeSet attrs, int defStyle) : base(context, attrs, defStyle)
    {
    }

    protected override void OnMeasure(int widthMeasureSpec, int heightMeasureSpec)
    {
        int heightMeasureSpec_custom = MeasureSpec.MakeMeasureSpec(int.MaxValue >> 2, MeasureSpecMode.AtMost);
        base.OnMeasure(widthMeasureSpec, heightMeasureSpec);

        ViewGroup.LayoutParams params2 = LayoutParameters;
        params2.Height = MeasuredHeight;
    }
}
禁用嵌套滚动:

if (Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.Lollipop)
{
    listView.NestedScrollingEnabled = false;
}
else
{
    ViewCompat.SetNestedScrollingEnabled(listView, false);
}

谢谢你的回答,我会试着把它转换成C#,这对我来说有点复杂,因为我对Java非常陌生谢谢你的回答,我会试着把它转换成C#,这对我来说有点复杂,因为我对Java非常陌生