4

I use https://github.com/nhaarman/ListViewAnimations to implement the drag&drop, swipe to delete etc. But there are problems the first image can scroll the list but cannot drag&drop (it drop to the same location and it don't enter the onItemMoved)

The second image I remove the linearLayout. Now I can scroll and drag&drop but the layout is broken.

I think I will measure the whole screen height the directly fix the height of NestedScrollView. But I think it may not a best practice for this problem. My question was is there a better way to fix my problems?

The third image I remove the linearLayout and NestedScrollView so user cannot scroll the list.

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>

UmAnusorn
  • 10,420
  • 10
  • 72
  • 100

1 Answers1

0

This is my current solution. I think there is a better solution.

The actionBar height from this topic

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;
}
BlueWizard
  • 372
  • 4
  • 19
UmAnusorn
  • 10,420
  • 10
  • 72
  • 100