简体   繁体   中英

Issue using “AndroidSwipeLayout” Library of “daimajia” for version above 4.4 (kitkat)- BackView Swipe more from the right side

I've using AndroidSwipeLayout Library from "daimajia" Android Swipe Layout

It's working fine although for version above 4.4 Kitkat. The backview of the swipe layout is swipe more from the right side..

plz refer to the attached images both for below 4.4 kitkat and above version

Android Swipe Layout Works Perfectly for Android Ver. 4.2 (jellybean) below Kitkat

Android Swipe Layout适用于Android Ver。在Kitkat下面的4.2(软糖)

Android Swipe Layout - backview slides more from right for Android ver. 4.4 Kitkat and above

Android Swipe Layout  -  backview从右侧滑动更多Android版本。 4.4 Kitkat及以上

I've made some research and find out that something is wrong with drag distance. For now I've figured out work around. This cause strange jump on animation but in the end backview will go to proper position. I'll try to find better solution.

In class "SwipeLayout" we need to modify "open" method:

public void open(boolean smooth, boolean notify) {
    View surface = getSurfaceView(), bottom = getCurrentBottomView();
    if (surface == null) {
        return;
    }
    int dx, dy;
    Rect rect = computeSurfaceLayoutArea(true);
    // if (smooth) {
    // mDragHelper.smoothSlideViewTo(surface, rect.left, rect.top);
    // } else {
    dx = rect.left - surface.getLeft();
    dy = rect.top - surface.getTop();
    surface.layout(rect.left, rect.top, rect.right, rect.bottom);
    if (getShowMode() == ShowMode.PullOut) {
        Rect bRect = computeBottomLayoutAreaViaSurface(ShowMode.PullOut, rect);
        if (bottom != null) {
            bottom.layout(bRect.left, bRect.top, bRect.right, bRect.bottom);
        }
    }
    if (notify) {
        dispatchRevealEvent(rect.left, rect.top, rect.right, rect.bottom);
        dispatchSwipeEvent(rect.left, rect.top, dx, dy);
    } else {
        safeBottomView();
    }
    // }
    invalidate();
}

i've solve the issue ...

this is my xml for swipelayout

<?xml version="1.0" encoding="utf-8" ?>
<com.synsoft.foodjini.swipelib.SwipeLayout         xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:swipe="http://schemas.android.com/tools"
     android:id="@+id/swipe"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     swipe:leftEdgeSwipeOffset="0dp"
     swipe:rightEdgeSwipeOffset="0dp"
     swipe:show_mode="lay_down"
     android:background="@color/colorPrimary">

<LinearLayout
    android:id="@+id/cart.item.back"
    android:layout_width="600px"
    android:layout_height="match_parent"
    android:background="@color/colorPrimary"
    android:orientation="horizontal"
    android:gravity="center"
    android:tag="Bottom3"
    android:weightSum="10"
    android:paddingLeft="6dp"
    android:paddingRight="6dp"
    android:paddingTop="12dp"
    android:paddingBottom="12dp">

    <ImageView
        android:id="@+id/edit"
        android:layout_width="120dp"
        android:layout_height="match_parent"
        android:scaleType="centerInside"
        android:layout_gravity="center"
        android:src="@drawable/cart_main_item_edit_ico"/>
    <ImageView
        android:id="@+id/delete"
        android:layout_width="120dp"
        android:scaleType="centerInside"
        android:layout_gravity="center"
        android:layout_height="match_parent"
        android:src="@drawable/cart_main_item_delete_ico"/>

</LinearLayout>

<RelativeLayout
    android:id="@+id/cart.item.front"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:paddingLeft="6dp"
    android:paddingRight="6dp"
    android:paddingTop="12dp"
    android:paddingBottom="12dp"
    android:background="@android:color/white">

    <TextView
        android:id="@+id/quantities"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="2"
        android:textSize="18sp"
        android:textStyle="normal"/>

    <TextView
        android:id="@+id/cart.item.names"
        android:layout_width="220dp"
        android:layout_height="wrap_content"
        android:text="X Item Name Lorem Ipsum"
        android:layout_marginLeft="12dp"
        android:ellipsize="end"
        android:singleLine="true"
        android:textAllCaps="true"
        android:layout_toRightOf="@+id/quantities"
        android:textSize="18sp"
        android:textStyle="normal"/>

    <TextView
        android:id="@+id/cart.item.portions"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="small"
        android:layout_toRightOf="@+id/cart.item.names"
        android:layout_alignBottom="@+id/cart.item.names"
        android:textSize="13sp"
        android:textAllCaps="true"
        android:textStyle="normal"/>

    <TextView
        android:id="@+id/cart.item.prices"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="20.00"
        android:layout_alignParentRight="true"
        android:drawableLeft="@drawable/cart_item_rupee_ico"
        android:drawablePadding="6dp"
        android:layout_alignBottom="@+id/cart.item.names"
        android:textSize="16sp"
        android:textStyle="normal"/>

    <ImageView
        android:id="@+id/cart.item.divider1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/cart_main_item_sap"
        android:layout_marginTop="12dp"
        android:layout_below="@+id/cart.item.names"
        android:layout_alignLeft="@+id/cart.item.names"/>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:layout_below="@+id/cart.item.divider1"
        android:id="@+id/cart.item.addons.tag"
        android:layout_marginTop="12dp"
        android:layout_marginBottom="12dp">

    </LinearLayout>

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/cart_main_item_sap"
        android:layout_marginTop="6dp"
        android:layout_below="@+id/cart.item.addons.tag"
        android:layout_alignLeft="@+id/cart.item.names"/>
</RelativeLayout>

what i've done is matches the background of the SwipeLayout (parentlayout) and back view (swipeview) android:background="@color/colorPrimary".. so that if backview positioning is improper than the view doesn't seems so asymetric

Also change the show_mode of the SwipeLayout to lay_down and background of the frontview to white

hence this skip the issue found on kitkat and higher version.

although its not the proper solution.. in the future i have to study the lib and try to find why positioning is improper for kitkat n above

在此输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM