0

タッチ イベント (int x、int y、int タイプのイベント) を取得し、指定された情報で mapview(osmdroid) またはボタンを管理するアクティビティがあります。マップビューを覆う必要があるので、フレームレイアウトに配置して上部の画像を配置しました。上の画像が表示されている場合、下のマップビューをパンできません (ただし、ズームインとズームアウトはできます)。

これは私の 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 のタッチイベントを機能させるにはどうすればよいですか?

4

1 に答える 1