添加2個新功能(swipelayout +動畫)後,我的用戶界面會凍結。使用swipelayout凍結動畫
我有一個recyclerview包含電影對象。如果我添加/刪除/修改電影,我打電話給我的電影管理員,因爲有一個通知的概念(所有想要使用數據的視圖必須在該管理器上註冊)。 這一切工作正常之前,我添加了新的功能。
我用這個swipelayout: https://github.com/daimajia/AndroidSwipeLayout
目前的項目是這樣的:
刷卡後:
凍結始終是可重複的,如果我有4項。我滑動第二項並刪除它。然後它會像我想要的那樣消失。 在即時刷新「第二個項目」之後,會有10-15秒的凍結時間。
項目的佈局XML:適配器的
<com.daimajia.swipe.SwipeLayout
android:id="@+id/item_movie_swipe_layout"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:id="@+id/item_movie_swipe_bottom_wrapper"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="#ff0000">
<TextView
android:id="@+id/item_movie_bottom_delete_desc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableTop="@drawable/ic_delete_white_24dp"
android:text="@string/delete"
android:textColor="#fff"
android:layout_gravity="center"
android:padding="10dp"/>
</LinearLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="5dp">
<ImageView
android:id="@+id/item_movie_list_poster"
style="@style/image_border_style"
android:layout_width="68dp"
android:layout_height="100dp"
android:layout_marginRight="3dp"
android:background="@android:color/black"/>
<TextView
android:id="@+id/item_movie_list_name_year"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginBottom="3dp"
android:layout_toEndOf="@+id/item_movie_list_poster"
android:layout_toRightOf="@+id/item_movie_list_poster"
android:gravity="center|left"
android:padding="3dp" android:text="name"/>
<TextView
android:id="@+id/item_movie_list_genre"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_below="@+id/item_movie_list_name_year"
android:layout_marginBottom="3dp"
android:layout_toEndOf="@+id/item_movie_list_poster"
android:layout_toRightOf="@+id/item_movie_list_poster"
android:padding="3dp"
android:text="Drama - Komödie - Action" android:textColor="@color/item_textyear"
android:textSize="12dp"/>
<TextView
android:id="@+id/item_movie_list_viewed"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@id/item_movie_list_poster"
android:layout_toRightOf="@+id/item_movie_list_poster"
android:paddingLeft="3dp" android:text="Gesehen: "
android:textColor="@color/accept"
android:textSize="12dp"/>
</RelativeLayout>
</com.daimajia.swipe.SwipeLayout>
相關代碼:
@Override
public void onBindViewHolder(final CDMMoviesAdapter.IC_ViewHolder p_Holder, final int p_iPosition) {
// more unimportant code...
p_Holder.m_SwipeLayout.setShowMode(SwipeLayout.ShowMode.PullOut);
// Drag From Right
p_Holder.m_SwipeLayout.addDrag(SwipeLayout.DragEdge.Right, p_Holder.m_SwipeLayout.findViewById(R.id.item_movie_swipe_bottom_wrapper));
// Handling different events when swiping
p_Holder.m_SwipeLayout.addSwipeListener(new SwipeLayout.SwipeListener() {
@Override
public void onClose(SwipeLayout layout) {
//when the SurfaceView totally cover the BottomView.
}
@Override
public void onUpdate(SwipeLayout layout, int leftOffset, int topOffset) {
//you are swiping.
}
@Override
public void onStartOpen(SwipeLayout layout) {
}
@Override
public void onOpen(SwipeLayout layout) {
//when the BottomView totally show.
}
@Override
public void onStartClose(SwipeLayout layout) {
}
@Override
public void onHandRelease(SwipeLayout layout, float xvel, float yvel) {
//when user's hand released.
}
});
p_Holder.m_SwipeLayout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View p_View) {
if((((SwipeLayout) p_View).getOpenStatus() == SwipeLayout.Status.Close)) {
Intent l_Intent = new Intent();
Bundle l_Bundle = new Bundle();
l_Bundle.putLong(CDMMovieDetailsActivity.ARG_MOVIE, l_MovieID);
l_Intent.putExtras(l_Bundle);
l_Intent.setClass(l_Context, CDMMovieDetailsActivity.class);
l_Context.startActivity(l_Intent);
}
}
});
p_Holder.m_tvDelete.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View p_View) {
Animation l_DeleteAnimation = AnimationUtils.loadAnimation(l_Context, R.anim.slide_out);
l_DeleteAnimation.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
}
@Override
public void onAnimationRepeat(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
mItemManger.removeShownLayouts(p_Holder.m_SwipeLayout);
CDMMovieManager.getInstance().removeMovieID(m_List, m_MovieIDs.get(p_iPosition));
mItemManger.closeAllItems();
}
});
p_Holder.m_View.startAnimation(l_DeleteAnimation);
}
});
// mItemManger is member in RecyclerSwipeAdapter Class
mItemManger.bindView(p_Holder.itemView, p_iPosition);
// more unimportant code...
}
/**
* This class is the viewholder. For internal use only.
*/
public static class IC_ViewHolder extends RecyclerView.ViewHolder {
/**
* Constructor
*
* @param p_View the view
*/
public IC_ViewHolder(View p_View) {
super(p_View);
m_View = p_View;
m_SwipeLayout = (SwipeLayout) p_View.findViewById(R.id.item_movie_swipe_layout);
m_tvNameYear = (TextView) p_View.findViewById(R.id.item_movie_list_name_year);
m_ivPoster = (ImageView) p_View.findViewById(R.id.item_movie_list_poster);
m_tvGenre = (TextView) p_View.findViewById(R.id.item_movie_list_genre);
m_tvViewed = (TextView) p_View.findViewById(R.id.item_movie_list_viewed);
m_tvDelete = (TextView) p_View.findViewById(R.id.item_movie_bottom_delete_desc);
}
public View m_View;
public SwipeLayout m_SwipeLayout;
public TextView m_tvNameYear;
public ImageView m_ivPoster;
public TextView m_tvGenre;
public TextView m_tvViewed;
public TextView m_tvDelete;
}
在CDMMovieManager.getInstance().removeMovieID(m_List, m_MovieIDs.get(p_iPosition));
電影將被刪除,所有註冊的意見將被通報。在這種情況下,該適配器的片段將調用m_Adapter.notifyDataSetChanged();
動畫文件:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:duration="250"
android:fromXDelta="0%"
android:toXDelta="-100%"/>
</set>
我試過的東西View.clearAnimation()
或Animation.setAnimationListener(null)
,但我總是得到這個問題。 詢問您是否需要更多信息。
更新:
問題只有當我嘗試刷下一個項目occures。 (例如刪除第二個項目,之後嘗試刷新第二個項目的第三個項目 - >凍結我試圖刷卡的項目)。凍結只能在任何其他項目上滑動時刪除。
有什麼建議?我認爲問題在於動畫及其animationlistener的初始化。可能是管理器的'onAnimationEnd()'和'adapter.notifyDataSetChanged()'調用有同步問題。我不知道如何解決它。請幫忙。 – beeb