Issue
I have an activity that gets touch events (int x,int y, int type of event) and manage a mapview(osmdroid) or buttons with the given information. I have to cover the mapview so I placed it on a framelayout and place and upper image. If the upper image is visible, I am not able to pan the mapview underneath (but I am able to zoomIn and zoomOut).
this is my activity.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.client.Client"
tools:ignore="MergeRootFrame" >
<Button
android:id="@+id/Disconnect"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="3"
android:text="Disconnect/ Reconnect"
android:onClick="disconnect"/>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/frameLayout"
android:layout_below="@+id/disconnect">
<LinearLayout
android:id="@+id/memeContent"
android:layout_width="535px"
android:layout_height="350px"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:orientation="vertical"
>
<org.osmdroid.views.MapView
android:id="@+id/mapView"
android:layout_width="match_parent"
android:layout_height="300px"
>
</org.osmdroid.views.MapView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="50px"
>
<Button
android:id="@+id/ZoomIn"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="5"
android:onClick="ZoomIn"
android:text="Zoom In"
android:textSize="10dp" />
<Button
android:id="@+id/ZoomOut"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="5"
android:text="Zoom out"
android:onClick="ZoomOut"
android:textSize="10dp" />
</LinearLayout>
</LinearLayout>
<ImageView
android:id="@+id/imageViewFront"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:src="@drawable/image"
android:scaleType="centerCrop"
android:focusable="false"
android:focusableInTouchMode="false"/>
</FrameLayout>
</RelativeLayout>
and this is my MainActivity.java
public class MainActivity extends Activity {
LinearLayout memecontentView;
FrameLayout frameLayout;
ImageView imageViewFront;
View v;
MapView mapView;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_client_late);
imageViewFront= (ImageView) findViewById(R.id.imageViewFront);
//imageViewFront.setVisibility(View.GONE);
mapView = (MapView) findViewById(R.id.mapView);
mapView.setTileSource(TileSourceFactory.MAPQUESTOSM);
mapView.setMultiTouchControls(true);
mapView.setUseDataConnection(true);
memecontentView=(LinearLayout) findViewById(R.id.memeContent);
mapView.setBuiltInZoomControls(false);
}
//look for items in given coordinates
public void lookForButton(String msg){
String[] strArray = msg.split(" ");
final MotionEvent m;
final int x=Integer.valueOf(strArray[1]);
final int y=Integer.valueOf(strArray[2]);
int type=Integer.valueOf(strArray[3]);
switch (type){
case 2:
m = MotionEvent.obtain(226707,226707,0/*ACTION_DOWN*/,x,y,0);
runOnUiThread(new Runnable() {
public void run() {
memecontentView.dispatchTouchEvent(m);
}
});
break;
case 3:
m = MotionEvent.obtain(226707,226707,1/*ACTION_DOWN*/,x,y,0);
runOnUiThread(new Runnable() {
public void run() {
memecontentView.dispatchTouchEvent(m);
}
});
break;
case 5:
m = MotionEvent.obtain(226707,226707,2/*ACTION_MOVE*/,x,y,0);
runOnUiThread(new Runnable() {
public void run() {
memecontentView.dispatchTouchEvent(m);
}
});
break;
}
}
public void ZoomIn(View v){
mapView.getController().zoomIn();
}
public void ZoomOut(View v){
mapView.getController().zoomOut();
}
}
If the upper image is not visible (imageViewFront.setVisibility(View.INVISIBLE);
) the code above works great, but if I comment that line(I need to do it), I am not able to pan the mapview. I do not know if the upper image is stealing its touchevents. How can I prevent that? or how can I make MapView's touch events work even if mapView is under?
Solution
Try setting an onTouchEventListener that returns false for all touches. Apply that to any view that may be above the mapview, including layouts. That should make the touch go to the view underneath it, which will eventually hit the mapview.
frameLayout.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View arg0, MotionEvent event) {
return false;
}
});
Answered By - Gabe Sechan
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.