Android 这个布局有什么问题,双击
我试图做一些类似于此应用程序列表的事情 但这对我来说太难了,我不能很好地理解布局系统,所以我最终在RecyclerView中做了一些事情,矩形和图像按钮在左边,两个在右边。所有按钮都有一些功能。如果单击星号,它将从收藏夹中添加/删除星号,下载按钮将下载星号,正确的按钮是删除和更新 我使用谷歌的代码添加了clickListener函数Android 这个布局有什么问题,双击,android,xml,android-layout,android-recyclerview,Android,Xml,Android Layout,Android Recyclerview,我试图做一些类似于此应用程序列表的事情 但这对我来说太难了,我不能很好地理解布局系统,所以我最终在RecyclerView中做了一些事情,矩形和图像按钮在左边,两个在右边。所有按钮都有一些功能。如果单击星号,它将从收藏夹中添加/删除星号,下载按钮将下载星号,正确的按钮是删除和更新 我使用谷歌的代码添加了clickListener函数 public class RecyclerItemClickListener implements RecyclerView.OnItemTouchListen
public class RecyclerItemClickListener implements RecyclerView.OnItemTouchListener {
private OnItemClickListener mListener;
public interface OnItemClickListener {
public void onItemClick(View view, int position);
}
GestureDetector mGestureDetector;
public RecyclerItemClickListener(Context context, OnItemClickListener listener) {
mListener = listener;
mGestureDetector = new GestureDetector(context, new GestureDetector.SimpleOnGestureListener() {
@Override
public boolean onSingleTapUp(MotionEvent e) {
return true;
}
});
}
@Override
public boolean onInterceptTouchEvent(RecyclerView view, MotionEvent e) {
View childView = view.findChildViewUnder(e.getX(), e.getY());
if (childView != null && mListener != null && mGestureDetector.onTouchEvent(e)) {
mListener.onItemClick(childView, view.getChildPosition(childView));
}
return false;
}
@Override
public void onTouchEvent(RecyclerView view, MotionEvent motionEvent) {
}
}
并链接到正在执行此操作的侦听器:
mRecyclerView.addOnItemTouchListener(
new RecyclerItemClickListener(this, new RecyclerItemClickListener.OnItemClickListener() {
@Override public void onItemClick(View view, int position) {
Context context = getApplicationContext();
int duration = Toast.LENGTH_SHORT;
CharSequence text = "Item CLICKED";
Toast toast = Toast.makeText(context, text, duration);
toast.show();
}
即使我点击ImageButton(我为它设置了另一个函数),它也会显示单击的项目,这两个操作都被称为
我怎样才能使它与点击分离
但是我认为主要的问题是我的.xml,有人能看看有什么问题吗?我添加了很多亲戚,一个用于边框,另一个用于背景,第三个包含=x中的项目
这是回收商的物品清单
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="10dp"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/border"
android:padding="1dp"
>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:baselineAligned="false"
android:padding="5dp"
android:background="@android:color/white"
android:weightSum="1"
>
<LinearLayout android:id="@+id/thumbnail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5dip"
android:layout_alignParentLeft="true"
android:background="@android:color/white"
android:layout_marginRight="5dip">
<ImageButton
android:id="@+id/status"
android:background="@android:color/white"
android:layout_width="25dip"
android:layout_height="25dip"
/>
</LinearLayout>
<TextView
android:id="@+id/titulo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/thumbnail"
android:layout_toRightOf="@+id/thumbnail"
android:textColor="#040404"
android:typeface="sans"
android:background="@android:color/white"
android:textSize="15dip"
android:textStyle="bold"/>
<TextView
android:id="@+id/descricao"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#343434"
android:textSize="10dip"
android:layout_toRightOf="@+id/thumbnail"
android:background="@android:color/white"
android:layout_below="@+id/titulo" />
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@android:color/white"
android:paddingRight="10dp"
android:id="@+id/delete"
android:layout_toLeftOf="@+id/update"
android:padding="5dip"
android:onClick="deletarLei" />
<ImageButton android:layout_width="wrap_content"
android:id="@+id/update"
android:layout_height="wrap_content"
android:background="@android:color/white"
android:padding="5dip"
android:layout_alignParentRight="true"
/>
</RelativeLayout>
</RelativeLayout>
</RelativeLayout>
当我遇到类似问题时,布局中最顶部视图组上的标记通常可以解决问题。在您的情况下,这将是每个单元格/行中最顶部的视图组
android:genderantfocusability=“beforesandroid”
您甚至可以尝试在RecyclerView
上设置此选项。只有3个选项,根据我记忆中的before子代
应该可以使用,否则请尝试其他2个选项
我认为您可以在适配器的映像上放置一个
OnClickListener
,在循环视图上放置一个onItemClickListener。你的代码并不清楚你在做什么。我不明白你说的一切,我正在尝试用一些按钮来做一个列表,如果你点击ImageButton做函数a,如果你点击列表中的项目(而不是点击ImageButton),不管怎样做函数B谢谢回答=)