1

我已经为视图实现了 TouchListener。但是当触摸视图时,触摸事件没有响应。

我的代码,

 protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.map_fragment);
    imgDraw = (ImageView) findViewById(R.id.imgDraw);
    drawable=(View)findViewById(R.id.viewOnMap);
    progressDialog = new ProgressDialog(MapSearch.this);
    properties = new PropertyRequestService();
    GetGpsCoordinates getgpslatlng = new GetGpsCoordinates();
    getgpslatlng.getLocation(this);
    Latitude = getgpslatlng.getLatitude();
    Longitude = getgpslatlng.getLongitude();
    SupportMapFragment sfm = (SupportMapFragment) getSupportFragmentManager()
            .findFragmentById(R.id.map);
    map = sfm.getMap();
    map.setMapType(GoogleMap.MAP_TYPE_HYBRID);
    map.setMyLocationEnabled(true);


    final CameraPosition cameraPosition = new CameraPosition.Builder()
            .target(new LatLng(Latitude, Longitude)).zoom(15.0f).build();
    final CameraUpdate cameraUpdate = CameraUpdateFactory
            .newCameraPosition(cameraPosition);
    map.moveCamera(cameraUpdate);
    Marker placecurrentMarker = map
            .addMarker(new MarkerOptions()
                    .position(new LatLng(Latitude, Longitude))
                    .title("You are here!")
                    .snippet("")
                    .icon(BitmapDescriptorFactory
                            .fromResource(R.drawable.marker2)));
    new LoadViewTask().execute();
    drawable.setOnTouchListener(touchListener);

}


private OnTouchListener touchListener = new OnTouchListener() {

    @Override
    public boolean onTouch(View v, MotionEvent event) {
        Log.d("","on Touch");
        return false;
    }
};

xml,

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >

<View
    android:id="@+id/viewOnMap"
    style="@style/AppTheme"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >       
</View>

<fragment 
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="true" 
/>

</RelativeLayout> 

我调试并检查过,视图的触摸事件不起作用。请纠正我!!

任何帮助表示赞赏!

4

0 回答 0