我不知道whay当我设置longClickListener我的一个看法,它不火,这是我的布局:安卓:LongClickListener不工作
<?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">
<include
android:id="@+id/toolbar"
layout="@layout/toolbar" />
<RelativeLayout
android:layout_width="match_parent"
android:id="@+id/map"
android:layout_below="@+id/toolbar"
android:layout_height="match_parent">
</RelativeLayout>
<TextView
android:layout_margin="5dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="16"
android:id="@+id/zoom_level"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"/>
<RelativeLayout
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_marginBottom="5dp"
android:layout_marginRight="5dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:padding="10dp"
android:background="@drawable/zoom_in_bg"
android:layout_above="@+id/zoom_out"
android:src="@drawable/ic_add_black_24dp"
android:layout_width="wrap_content"
android:id="@+id/zoom_in"
android:layout_marginBottom="1dp"
android:layout_height="wrap_content"/>
<ImageView
android:padding="10dp"
android:background="@drawable/zoom_out_bg"
android:id="@+id/zoom_out"
android:layout_alignParentBottom="true"
android:src="@drawable/ic_remove_black_24dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</RelativeLayout>
</RelativeLayout>
,它是碎片
public class MapFragment extends BaseFragment implements View.OnLongClickListener
{
private View rootView;
private org.mapsforge.android.maps.MapView mapView ;
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
rootView = inflater.inflate(R.layout.fragment_navigation, container, false);
mapView = new org.mapsforge.android.maps.MapView(getContext());
mapView.setOnLongClickListener(this);
RelativeLayout relativeLayout = (RelativeLayout) rootView.findViewById(R.id.map);
relativeLayout.addView(mapView, new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT));
return rootView;
}
@Override
public boolean onLongClick(View view)
{
KLog.error("Long Click called");
return true;
}
}
我试过SetClickable(true)
,setLongClickable(true)
,setFocusable(true)
但我无法解决这个问题。解决方法是什么? 请指教
它不起作用 –
尝试在relativeLayout上设置监听器。看到我更新的答案。 –
我已经尝试过了,但它不起作用 –