我有一個活動獲取觸摸事件(int x,int y,int類型的事件)並使用給定的信息管理mapview(osmdroid)或按鈕。我必須覆蓋mapview,所以我把它放在一個framelayout和地方和上面的圖像。如果上面的圖像是可見的,我無法平移下面的mapview(但我可以放大和縮小)。在mapview中失去觸摸事件android(action_move)
這是我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>
,這是我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();
}
}
如果上的圖像是不可見的(imageViewFront.setVisibility(View.INVISIBLE);
)上面的代碼的偉大工程,但如果我評論該行(我需要這樣做),我無法平移mapview。我不知道上面的圖像是否在偷竊它的東西。我怎樣才能防止呢?或者即使mapView處於底層,我如何才能使MapView的觸摸事件起作用?
檢查您是否設置所有標誌,當啓用手勢激活如平移,縮放,拖動等mapView.getMap()。getUiSettings()。設置方法。你可能想重新訪問android:layout_height =「fill_parent」和android:layout_weight =「5」 –