Android:刷卡后点击在回收站项目上不起作用
Posted
技术标签:
【中文标题】Android:刷卡后点击在回收站项目上不起作用【英文标题】:Android: click doesn't work on Recycler Item after swiping 【发布时间】:2017-11-19 21:57:11 【问题描述】:我通过ItemTouchHelper.SimpleCallback
实现了Recycler
滑动效果,并在滑动后显示的后视图上放置了一些按钮。有趣的问题是,当我单击按钮时,它不起作用。我应该按两次,在第三次尝试中它们起作用了!!!这是一个 gif:
ItemTouchHelper.SimpleCallback simpleItemTouchCallback = new ItemTouchHelper.SimpleCallback(0,
ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT )
@Override
public int getMovementFlags(RecyclerView recyclerView,
RecyclerView.ViewHolder viewHolder)
int dragFlags = 0;
int swipeFlags = ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT;
return makeMovementFlags(dragFlags, swipeFlags);
@Override
public boolean isItemViewSwipeEnabled()
return true;
@Override
public boolean isLongPressDragEnabled()
return false;
@Override
public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, RecyclerView.ViewHolder target)
return false;
@Override
public void onChildDraw(Canvas c, RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, float dX, float dY, int actionState, boolean isCurrentlyActive)
((InvoiceItemListAdapter.ViewHolder)viewHolder).lunchSwipeLeftEffect(dX);
@Override
public void onSwiped(RecyclerView.ViewHolder viewHolder, int swipeDir)
;
recentInvoicesItemTouchHelper = new ItemTouchHelper(simpleItemTouchCallback);
recentInvoicesItemTouchHelper.attachToRecyclerView(recentInvoiceRecyclerView);
这是我的RecyclerView.ViewHolder
:
private class RecentInvoiceViewHolder extends RecyclerView.ViewHolder
private TextView price;
private TextView hours;
private TextView minutes;
private TextView desc;
private View color;
private View sent;
private View swipeActionsView;
private View frontView;
private Button print;
private Button cancelSwipe;
boolean swiped = false;
public RecentInvoiceViewHolder(View view)
super(view);
price = (TextView) view.findViewById(R.id.invoice_review_in_day_price);
hours = (TextView) view.findViewById(R.id.invoice_review_in_day_hours);
minutes = (TextView) view.findViewById(R.id.invoice_review_in_day_minutes);
desc = (TextView) view.findViewById(R.id.invoice_review_in_day_decs);
color = view.findViewById(R.id.invoice_review_in_day_color);
sent = view.findViewById(R.id.invoice_review_in_day_sent_check);
swipeActionsView = view.findViewById(R.id.swipe_actions);
frontView = view.findViewById(R.id.front_view);
print = (Button) view.findViewById(R.id.print_recent_invoice);
cancelSwipe = (Button) view.findViewById(R.id.cancel_swipe);
cancelSwipe.setOnClickListener(new View.OnClickListener()
@Override
public void onClick(View v)
frontView.setTranslationX(0);
frontView.setVisibility(View.VISIBLE);
swiped = false;
);
public void lunchSwipeEffect(float dx)
if(!swiped)
frontView.setTranslationX(dx);//TranslationX(dx);
if(Math.abs(dx)> frontView.getMeasuredWidth())
swiped = true;
frontView.setVisibility(View.GONE);
最后这是我的ViewHolder
布局:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_
android:layout_
android:layout_margin="@dimen/archived_right_one_day_item_margin"
android:clipChildren="false"
android:clipToPadding="false">
<TableLayout
android:id="@+id/swipe_actions"
android:layout_
android:layout_
android:stretchColumns="0,1,2"
android:clickable="false">
<TableRow
android:layout_weight="1"
>
<ir.masna.hetab.views.IranFontButton
android:id="@+id/print_recent_invoice"
android:layout_
android:layout_
android:textSize="@dimen/archived_right_one_day_item_time_font"
android:gravity="center"
android:text="print"
style="@style/CustomFontStyleYekan"
android:layout_column="0"/>
<ir.masna.hetab.views.IranFontButton
android:layout_
android:layout_
android:textSize="@dimen/archived_right_one_day_item_time_font"
android:gravity="center"
android:text="print"
style="@style/CustomFontStyleYekan"
android:layout_column="1"/>
<ir.masna.hetab.views.IranFontButton
android:layout_
android:layout_
android:textSize="@dimen/archived_right_one_day_item_time_font"
android:gravity="center"
android:text="print"
style="@style/CustomFontStyleYekan"
android:layout_column="2"/>
</TableRow>
<TableRow
android:layout_weight="1">
<ir.masna.hetab.views.IranFontButton
android:id="@+id/cancel_swipe"
android:layout_
android:layout_
android:textSize="@dimen/archived_right_one_day_item_time_font"
android:gravity="center"
android:text="cancel"
style="@style/CustomFontStyleYekan"
android:layout_column="0"/>
<ir.masna.hetab.views.IranFontButton
android:layout_
android:layout_
android:textSize="@dimen/archived_right_one_day_item_time_font"
android:gravity="center"
android:text="print"
style="@style/CustomFontStyleYekan"
android:layout_column="1"/>
<ir.masna.hetab.views.IranFontButton
android:layout_
android:layout_
android:textSize="@dimen/archived_right_one_day_item_time_font"
android:gravity="center"
android:text="print"
style="@style/CustomFontStyleYekan"
android:layout_column="2"/>
</TableRow>
</TableLayout>
<RelativeLayout
android:id="@+id/front_view"
android:layout_
android:layout_
android:background="#fff"
android:clickable="true"
>
<View
android:id="@+id/invoice_review_in_day_color"
android:layout_
android:layout_
android:layout_alignParentRight="true"
android:background="@drawable/invoice_review_box_radius_right_shape"/>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_
android:layout_
android:layout_toLeftOf="@+id/invoice_review_in_day_color"
android:layout_alignParentLeft="true"
android:background="@drawable/invoice_review_main_box_radius_shape"
android:padding="@dimen/archived_right_one_day_item_border">
<LinearLayout
android:layout_
android:layout_
android:layout_weight="@integer/archived_right_one_day_item_top_invoice_section_weight"
android:orientation="horizontal"
android:background="@drawable/invoice_review_box_radius_top_left_shape"
android:padding="@dimen/archived_right_one_day_item_top_section_padding">
<LinearLayout
android:layout_
android:layout_
android:layout_weight="1"
android:orientation="horizontal">
<ir.masna.hetab.views.IranFontTextView
android:id="@+id/invoice_review_in_day_hours"
android:layout_
android:layout_
android:layout_weight="1"
android:layout_marginLeft="@dimen/archived_right_one_day_item_time_margin"
android:textSize="@dimen/archived_right_one_day_item_time_font"
android:textColor="@color/archived_right_one_day_item_time_text_color"
android:gravity="center"
android:background="@drawable/clock_background"
style="@style/CustomFontStyleYekan"/>
<ir.masna.hetab.views.IranFontTextView
android:layout_
android:layout_
android:textSize="@dimen/archived_right_one_day_item_time_separator_font"
android:textColor="@color/archived_right_one_day_item_time_text_color"
android:text=":"
android:layout_marginTop="@dimen/archived_right_one_day_item_time_separator_margin_top"/>
<ir.masna.hetab.views.IranFontTextView
android:id="@+id/invoice_review_in_day_minutes"
android:layout_
android:layout_
android:layout_weight="1"
android:layout_marginRight="@dimen/archived_right_one_day_item_time_margin"
android:textSize="@dimen/archived_right_one_day_item_time_font"
android:textColor="@color/archived_right_one_day_item_time_text_color"
android:gravity="center"
android:background="@drawable/clock_background"
style="@style/CustomFontStyleYekan"/>
</LinearLayout>
<LinearLayout
android:layout_
android:layout_
android:layout_weight="1"
android:orientation="vertical">
<ir.masna.hetab.views.IranFontTextView
android:layout_
android:layout_
android:text="@string/archived_right_one_day_item_total_title"
android:textColor="#6d6d6d"
android:textSize="@dimen/archived_right_one_day_item_price_title_font"
android:gravity="bottom|right"
android:includeFontPadding="false"
android:layout_alignParentRight="true"
style="@style/CustomFontStyleYekan"/>
<ir.masna.hetab.views.AutoResize.AutoResizeTextView
android:id="@+id/invoice_review_in_day_price"
android:layout_
android:layout_
android:textSize="@dimen/archived_right_one_day_item_price_font"
android:gravity="top|right"
android:includeFontPadding="false"
android:maxLines="1"
style="@style/CustomFontStyleYekan"/>
</LinearLayout>
</LinearLayout>
<RelativeLayout
android:layout_
android:layout_
android:layout_weight="@integer/archived_right_one_day_item_bottom_invoice_section_weight"
android:background="@drawable/invoice_review_box_radius_bottom_left_shape">
<ir.masna.hetab.views.IranFontTextView
android:id="@+id/invoice_review_in_day_decs"
android:layout_
android:layout_
android:gravity="center_vertical|right"
android:textColor="@color/archived_right_one_day_item_time_text_color"
android:textSize="@dimen/archived_right_one_day_item_desc_font"
android:padding="@dimen/archived_right_one_day_item_desc_padding"
android:layout_toRightOf="@+id/invoice_review_in_day_sent_check"
android:ellipsize="end"
android:maxLines="1"
style="@style/CustomFontStyleYekan" />
<View
android:id="@+id/invoice_review_in_day_sent_check"
android:layout_
android:layout_
android:layout_marginBottom="8dp"
android:layout_marginLeft="8dp"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:gravity="center"
android:background="@drawable/tick"/>
</RelativeLayout>
</LinearLayout>
</RelativeLayout>
</FrameLayout>
recyclerView 位于NestedScrollView
中,具有折叠工具栏效果。
哪些视图消耗了两次首次点击?!
【问题讨论】:
顺便说一句,你有没有找到运气?我陷入了同样的境地.. 有人找到解决此问题的方法吗? 【参考方案1】:ItemTouchHelper
正在抓住来自RecyclerView
的触摸
【讨论】:
以上是关于Android:刷卡后点击在回收站项目上不起作用的主要内容,如果未能解决你的问题,请参考以下文章
iFrame allowFullScreen 属性在 Android WebView 上不起作用
React native TouchableOpacity onPress 在 Android Build (APK) 上不起作用
选择器按钮在我的 android 上的按钮上不起作用。如何解决?