- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我通过 ItemTouchHelper.SimpleCallback
实现了 Recycler
滑动效果,并在滑动后显示的后 View 上放置了一些按钮。有趣的问题是,当我点击按钮时,它不起作用。我应该按下它们两次,在第三次尝试中它们起作用了!!!这是一张动图:
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_width="match_parent"
android:layout_height="@dimen/archived_right_one_day_invoice_item_height"
android:layout_margin="@dimen/archived_right_one_day_item_margin"
android:clipChildren="false"
android:clipToPadding="false">
<TableLayout
android:id="@+id/swipe_actions"
android:layout_width="match_parent"
android:layout_height="match_parent"
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_width="wrap_content"
android:layout_height="wrap_content"
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_width="wrap_content"
android:layout_height="wrap_content"
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_width="wrap_content"
android:layout_height="wrap_content"
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_width="wrap_content"
android:layout_height="wrap_content"
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_width="wrap_content"
android:layout_height="wrap_content"
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_width="wrap_content"
android:layout_height="wrap_content"
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_width="match_parent"
android:layout_height="match_parent"
android:background="#fff"
android:clickable="true"
>
<View
android:id="@+id/invoice_review_in_day_color"
android:layout_width="@dimen/archived_right_one_day_item_colored_view_width"
android:layout_height="match_parent"
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_width="match_parent"
android:layout_height="match_parent"
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_width="match_parent"
android:layout_height="0px"
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_width="0px"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="horizontal">
<ir.masna.hetab.views.IranFontTextView
android:id="@+id/invoice_review_in_day_hours"
android:layout_width="0px"
android:layout_height="match_parent"
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_width="wrap_content"
android:layout_height="match_parent"
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_width="0px"
android:layout_height="match_parent"
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_width="0px"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical">
<ir.masna.hetab.views.IranFontTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
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_width="match_parent"
android:layout_height="wrap_content"
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_width="match_parent"
android:layout_height="0px"
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_width="match_parent"
android:layout_height="match_parent"
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_width="20dp"
android:layout_height="20dp"
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
中,具有折叠工具栏效果。
哪些 View 会消耗两次第一次点击?!
最佳答案
ItemTouchHelper
正在抓取来自 RecyclerView
的触摸
关于Android:滑动后点击对 Recycler Item 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44600828/
在标题为“Managing Bitmap Memory”的文档中,您可以找到以下声明: Caution: You should use recycle() only when you are sure
另一个Recycler View里面有一个Recycler View,都需要垂直滚动。外部 Recycler View 可以正确滚动,但内部 Recycler View 不能。 代码如下: Linea
几天前,我们在 Play 商店发布了一个应用程序,它处理高质量的位图并且完全是关于编辑它们。 当我们意识到 20% 的设备出现内存不足错误时,一切进展顺利。所以我们检查了我们的代码,发现 Androi
我有两个 Activity :MainActivity 和 Activity2。 MainActivity 只需通过 Intent 打开第二个。 要从 Activity2 返回到 MainActivi
我想在 Jetpack compose 中创建以下布局。 我尝试在垂直可滚动框中创建两个列表,但这是不可能的,因为我得到了这个错误: “java.lang.IllegalStateException:
我在 xml 中使用以下代码生成两个 RadioButtons,它们之间有分隔线: 这工作正常,并且在 ViewPager
我使用以下 xml 可绘制对象作为我的 recyclerview 列表项的背景。 touch_selector.xml touch_selector_base.xml
我进行了很多搜索,我所做的是创建一个项目列表,其中包含简单的数字并具有选中和未选中的复选框,因此当我快速点击列表时,它会崩溃并生成 ArrayIndexOutOfBound Exception 所以我
我正在尝试添加一些点击动画 as shown here在我的回收者看来,但没有成功。这是我的一些代码。 在我的 Activity 中 @Override protected void onCreate
我在回收站 View 中有一个歌曲列表。我需要更改之前播放的行的背景颜色。 所以在我的onBindViewHolder我有这个。 if(activeAudioIndex
对于房间分贝的目的。我想在 Recycler View 中运行一些协程。 必要的挂起函数作为类参数处理: class RecyclerAdapter (private val exist : su
我想创建一个列表,例如 To-Do List。 在此用户可以选择/取消选择一个项目,根据他们的优先级重新排序。在当前情况下,我可以使用 为他们提供上述所有功能。 ItemTouchHelper.Sim
我必须与 IBinder 合作s 和 Parcel s。我已经浏览了所有 IBinder , Binder , 和 Parcel文档,找不到任何关于何时调用 Parcel.recycle 的内容(我也
我正在尝试将回收站 View 滚动到底部,但问题是我的行项目高度是否大于滚动停止在项目顶部的屏幕高度。是否可以手动滚动到回收站 View 的最底部? recyclerView.scrollToPosi
我的 Activity 有一个谷歌的 ViewModel 来获取一些模型项目。然后将这些项目转换为 RecyclerView 的适配器项目。一个 RecyclerView 还支持多种类型的适配器项。
我目前正在开发一个 Azure 项目,该项目可在本地使用模拟器资源 100% 运行。我现在正在尝试部署辅助角色,但遇到了一个问题,我不确定如何解决。 在我的 Azure 门户中部署辅助角色后,这两个实
我正在为我的回收站 View 项目使用约束布局。为了动画(展开/折叠)它们,我使用约束集动画。开场动画在所有项目上运行良好。关闭动画也运行良好,但是当关闭动画在不是最后一个的项目上开始时,所有项目在动
我一直在尝试让自定义Recycler View 适配器工作。我不太明白为什么它不起作用。我觉得奇怪的是自定义适配器的代码不执行(因为当我在那里放置断点时它不会中断)并且我确定我绑定(bind)了自定义
我想使用 Firebase 制作一个杂务应用程序,它有 2 个输入:描述和类。每当我运行该应用程序时,显示的屏幕都是空白的(标题除外)没有可能显示问题的明确指示或错误。这些是最富有成果的 logCat
我想使用 Firebase 制作一个杂务应用程序,它有 2 个输入:描述和类。每当我运行该应用程序时,显示的屏幕都是空白的(标题除外)没有明确的指示或错误可能显示问题。这些是最富有成果的 logCat
我是一名优秀的程序员,十分优秀!