NestedScrollView高度不是match_parent

时间:2015-09-15 10:15:15

标签: android android-layout

我使用https://github.com/nhaarman/ListViewAnimations来实现拖放,滑动以删除等等。但是有问题第一张图片可以滚动列表但不能拖放(它放到同一个位置而不是输入onItemMoved)

第二张图片我删除了linearLayout。现在我可以滚动并拖放但布局已破坏。

我想我将测量整个屏幕高度直接修复NestedScrollView的高度。但我认为这可能不是解决这个问题的最佳方法。 我的问题是有更好的方法来解决我的问题吗?

第三张图片我删除了linearLayout和NestedScrollView,因此用户无法滚动列表。

enter image description here

enter image description here

enter image description here

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
          xmlns:app="http://schemas.android.com/apk/res-auto"
          android:id="@+id/drawerLayout"
          android:orientation="vertical"
          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:background="@color/green_400"
        android:layout_height="match_parent">

    <android.support.design.widget.AppBarLayout
            android:layout_width="match_parent"
            android:layout_height="180dp"

            >

        <android.support.design.widget.CollapsingToolbarLayout
                android:id="@+id/collapsingToolbarLayout"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                app:contentScrim="@color/transparent"
                app:expandedTitleMarginStart="@dimen/expanded_toolbar_title_margin_start"

                app:layout_scrollFlags="scroll|exitUntilCollapsed"
                >
            <!--app:layout_scrollFlags="scroll|exitUntilCollapsed"|-->
            <ImageView
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:scaleType="centerCrop"
                    android:src="@drawable/header"/>

            <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/ThemeOverlay.AppCompat.Light"
                    android:background="@android:color/transparent"/>


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

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

    <android.support.v4.widget.NestedScrollView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fillViewport="true"
            android:background="@color/red_600"
            app:layout_behavior="@string/appbar_scrolling_view_behavior">

        <LinearLayout
                android:layout_width="fill_parent"
                android:layout_height="wrap_content">

            <com.nhaarman.listviewanimations.itemmanipulation.DynamicListView
                    android:id="@+id/listViewTaskInComplete"
                    android:layout_width="match_parent"

                    android:layout_height="match_parent"/>

        </LinearLayout>


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

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

</android.support.design.widget.CoordinatorLayout>

1 个答案:

答案 0 :(得分:0)

这是我目前的解决方案。我认为有更好的解决方案。

this topic

的actionBar高度
public static float getListHeight (Activity activity) {
    DisplayMetrics displayMetrics = getScreenSize (activity);
    float height = displayMetrics.heightPixels;
    float density = activity.getResources ().getDisplayMetrics ().density;
    float headerHeight = activity.getResources ().getDimension (R.dimen.landing_header_max_height) / density;
    float screenHeight = height / density;
    int actonBarHeight = (int) (getActionBarHeight (activity) / density);
    //Log.d ( "Utility", "ScreenHeight" + screenHeight + "headerHeight=" + headerHeight +"dense="+density+"actionBarHeight"+actonBarHeight);
    return ( screenHeight - headerHeight )*density-actonBarHeight;
}

public static int getActionBarHeight(Activity activity){
    TypedValue tv = new TypedValue();
    if (activity.getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true)) {
        return  TypedValue.complexToDimensionPixelSize(tv.data,activity.getResources().getDisplayMetrics());
    }
    return -1;
}

public static DisplayMetrics getScreenSize (Activity activity) {
    Display display = activity.getWindowManager ().getDefaultDisplay ();
    DisplayMetrics outMetrics = new DisplayMetrics ();
    display.getMetrics (outMetrics);

    return outMetrics;
}