I have two views in my activity in my Android app. One View (we'll call this viewOne) has a bunch of SeekBars while the other view (we'll call this viewTwo) contains a Drawable that is redrawn whenever a user touches it.
viewTwo has an OnTouchListener. The issue is that when I touch viewOne to move a SeekBar, viewTwo's touch listener is getting called and this creates a huge amount of lag due to it needing to redraw every time the listener is called.
Why is this happening and how can I stop it? Thanks!
EDIT:
Main Activity Layout:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="1"
android:orientation="vertical">
<com.rfoo.viewOne
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.5"
android:id="#+id/vOne"/>
<com.rfoo.viewTwo
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.5"
android:id="#+id/vTwo"/>
</LinearLayout>
View One Layout:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="1"
android:orientation="vertical">
<SeekBar
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.25"
android:id="#+id/sb1"/>
<SeekBar
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.25"
android:id="#+id/sb2"/>
<SeekBar
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.25"
android:id="#+id/sb3"/>
<SeekBar
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.25"
android:id="#+id/sb4"/>
</LinearLayout>
View Two Layout:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<View
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/myView"/>
</LinearLayout>
Main Activity Code:
public class MainActivity extends AppCompatActivity implements View.OnTouchListener {
#Override
protected void onCreate(Bundle savedInstanceState) {
// Initializations here...
// And then:
View viewTwo = (View)findViewById(R.id.vTwo);
viewTwo.setOnTouchListener(this);
}
#Override
public boolean onTouch(View v, MotionEvent event) {
if (v.getId() == R.id.vTwo) {
vTwo.invalidate();
}
}
}
You implemented View.OnTouchListener but you haven't used it. I think your purpose is using that to trigger onTouch()
public class MainActivity extends AppCompatActivity implements View.OnTouchListener {
#Override
protected void onCreate(Bundle savedInstanceState) {
// Initializations here...
// And then:
View viewTwo = (View)findViewById(R.id.vTwo);
viewTwo.setOnTouchListener(this);
}
#Override
public boolean onTouch(View v, MotionEvent event) {
if (v.getId() == R.id.vTwo) { // you can use viewTwo instead of v as well
viewTwo.invalidate();
}
}
}
Well i am almost sure the problem is because the unused nested layouts i tried this and worked fine for me :
public class exampleActivity extends AppCompatActivity {
private static final String DEBUG_TAG = "Motion event";
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.example_layout);
findViewById(R.id.myView).setOnTouchListener(new View.OnTouchListener() {
#Override
public boolean onTouch(View v, MotionEvent event) {
return (v.getId() == R.id.myView) &&
handleGesture(MotionEventCompat.getActionMasked(event));
}
});
}
private boolean handleGesture(int action) {
switch(action) {
case (MotionEvent.ACTION_DOWN) :
Log.d(DEBUG_TAG, "Action was DOWN");
return true;
case (MotionEvent.ACTION_MOVE) :
Log.d(DEBUG_TAG,"Action was MOVE");
return true;
case (MotionEvent.ACTION_UP) :
Log.d(DEBUG_TAG,"Action was UP");
return true;
case (MotionEvent.ACTION_CANCEL) :
Log.d(DEBUG_TAG,"Action was CANCEL");
return true;
case (MotionEvent.ACTION_OUTSIDE) :
Log.d(DEBUG_TAG,"Movement occurred outside bounds " +
"of current screen element");
return true;
default :
return false;
}
}
}
And this is my xml layout :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<SeekBar
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight=".25"
android:id="#+id/sb1"/>
<SeekBar
android:layout_width="match_parent"
android:layout_weight=".25"
android:layout_height="0dp"
android:id="#+id/sb2"/>
<SeekBar
android:layout_width="match_parent"
android:layout_weight=".25"
android:layout_height="0dp"
android:id="#+id/sb3"/>
<SeekBar
android:layout_width="match_parent"
android:layout_weight=".25"
android:layout_height="0dp"
android:id="#+id/sb4"/>
<View
android:layout_weight="1"
android:background="#color/appframe__colorAccent"
android:layout_width="match_parent"
android:layout_height="0dp"
android:id="#+id/myView"/>
</LinearLayout>
Related
I have problem with setOnLongClickListener. When I use this method I want the dialog, which will open, to automatically close by itself (which the method's return false should do) when I take my finger off the screen. Is it possible to do this with this method, or are there other suitable methods?
Create Dialog
protected void showDialogLongClick(final int position){
final Dialog dialog = new Dialog(activity);
dialog.setCancelable(true);
View v = activity.getLayoutInflater().inflate(R.layout.onlongclick_card_mygift,null);
dialog.setContentView(v);
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
nameLong = v.findViewById(R.id.name_longclick);
descriptionLong = v.findViewById(R.id.gift_description);
addressLong = v.findViewById(R.id.gift_address);
imageCategory = v.findViewById(R.id.small_category);
nameLong.setText(myGift.get(position).getName());
descriptionLong.setText(myGift.get(position).getDescription());
addressLong.setText(myGift.get(position).getAddress());
String cat = myGift.get(position).getCategory();
changeCategoryImage(cat, imageCategory);
dialog.show();
}
Listener
holder.card.setOnLongClickListener(new View.OnLongClickListener() {
#Override
public boolean onLongClick(View v) {
showDialogLongClick(position);
return false;
}
});
XML card dialog
<?xml version="1.0" encoding="utf-8"?>
<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_gravity="center"
app:cardCornerRadius="10dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/background_card_mygift"
android:orientation="vertical"
android:padding="10dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="#+id/name_longclick"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text=""
android:textColor="#FFFFFF"
android:textSize="25sp"
android:layout_weight="1"
android:layout_marginEnd="10dp"/>
<ImageView
android:id="#+id/small_category"
android:layout_weight="0"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_gravity="center_vertical"/>
</LinearLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text=""
android:textColor="#F44336"
android:textSize="22sp"/>
<TextView
android:id="#+id/gift_description"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text=""
android:textColor="#FFFFFF"
android:textSize="20sp"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text=""
android:textColor="#F44336"
android:textSize="22sp"/>
<TextView
android:id="#+id/gift_address"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text=""
android:textColor="#FFFFFF"
android:textSize="20sp"/>
</LinearLayout>
</androidx.cardview.widget.CardView>
view.setOnTouchListener(new View.OnTouchListener() {
#Override
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_UP) {
//Dismiss the dialog
}
return false;
}
});
view.setOnLongClickListener(new View.OnLongClickListener() {
#Override
public boolean onLongClick(View view) {
//Create the dialog
return true;
}
});
Use setOnLongClickListener for creating the dialog and use setOnTouchListener for dismissing the dialog.
So you should add setOnTouchListener to the view. Call dialog.dismiss() when MotionEvent action is MotionEvent.ACTION_UP (user lifts his finger).
If the view is inside a scroll view the views onTouchListener does not get called. A simple solution is to add an onTouchListener to the scroll view and dismiss the dialog when user lifts his finger.
scrollView.setOnTouchListener( new View.OnTouchListener(){
#Override
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_UP) {
//Dismiss the dialog
return true;
}
return false;
}
});
In my fragment I have a TextView and underneath there are two buttons.
I need to implement a OnTouchListener to do two things:
When I rotate my two fingers, the TeXtView will rotate
When I tap the TeXtView, the buttons underneath are called
Right now it doesnt work but I cant find better solution.
XML:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_centerInParent="true"
tools:context="com.fjord.yalc.MainActivity"
android:id="#+id/player_fragment">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<Button
android:id="#+id/buttonUp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#android:color/transparent"/>
<Button
android:id="#+id/buttonDown"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#android:color/transparent"/>
</LinearLayout>
<com.fjord.yalc.AutoResizeTextView
android:id="#+id/player"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:maxLines="1"
android:text="#string/normal_start"
android:textAppearance="#android:style/TextAppearance.DeviceDefault.DialogWindowTitle"
android:textColor="#color/colorLightGray"
android:textSize="300sp"
android:textStyle="bold"
android:layout_marginLeft="25dp"
android:layout_marginRight="25dp"
android:layout_alignParentTop="true"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_alignParentStart="true" />
</RelativeLayout>
JAVA:
Btn1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
player.setText(String.valueOf(++life));
}
});
mRotationDetector = new RotationGestureDetector(this);
TV.setOnTouchListener(new View.OnTouchListener() {
#Override
public boolean onTouch(View v, MotionEvent event) {
int maskedAction = event.getActionMasked();
switch (maskedAction) {
case MotionEvent.ACTION_DOWN: {
return false;
}
case MotionEvent.ACTION_OUTSIDE: {
return false;
}
case MotionEvent.ACTION_MOVE: {
mRotationDetector.onTouchEvent(event);
break;
}
}
return true;
}
});
Ok, after a week I found the answer. I needed to dispatch my MotionEvent to parent of my buttons using dispatchTouchEvent. ACTION_POINTER_DOWN is for checking if user uses two fingers.
Now rotation goes to mRotationDetector and taps goes to onClickListeners of the buttons underneath the TextView player.
JAVA:
player.setOnTouchListener(new View.OnTouchListener() {
#Override
public boolean onTouch(View v, MotionEvent event) {
MotionEvent me = MotionEvent.obtain(event);
mRotationDetector.onTouchEvent(me);
switch (event.getActionMasked()){
case (MotionEvent.ACTION_DOWN):
flag=true;
break;
case(MotionEvent.ACTION_POINTER_DOWN):
flag=false;
break;
}
buttons.dispatchTouchEvent(event);
return true;
}
});
I am working on an Android application using C# in Xamarin. In my axml file, I have a LinearLayout with a certain ID that I have assigned a onTouchListener to. The problem is that as long as the buttons I have in my design are on top of the linearLayout, the onTouchListener is never triggered. If I set one of the buttons to invisible, then it works.
Is it possible to still have the onTouchListener react even though there are Controls in the way?
This is my axml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/LinearLayout1"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:orientation="vertical">
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:orientation="horizontal"
android:layout_weight="1">
<Button
android:id="#+id/button1"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="1"
android:layout_marginBottom="0.0dp"
android:background="#android:color/holo_green_light"
android:soundEffectsEnabled="false" />
<Button
android:id="#+id/button2"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="2"
android:background="#android:color/holo_blue_light" />
</LinearLayout>
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_weight="1">
<Button
android:id="#+id/button3"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="3"
android:background="#android:color/holo_red_light" />
<Button
android:id="#+id/button4"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="4"
android:background="#android:color/holo_orange_light" />
</LinearLayout>
</LinearLayout>
This is how I set the onTouchlistener for the linearLayout:
LinearLayout linLay = FindViewById<LinearLayout>(Resource.Id.LinearLayout1);
linLay.SetOnTouchListener(new MyTouchListener(this));
This is a custom touch listener class:
public class MyTouchListener : Java.Lang.Object, View.IOnTouchListener
{
Context activityContext;
public MyTouchListener(Context ac)
{
activityContext = ac;
}
public bool OnTouch(View v, MotionEvent e)
{
float x = 0.0f;
float y = 0.0f;
if (e.Action == MotionEventActions.Down)
{
// do stuff
x = e.GetX();
y = e.GetY();
Toast.MakeText(activityContext, x.ToString(), ToastLength.Short).Show();
return true;
}
//if (e.Action == MotionEventActions.Up)
//{
// // do other stuff
// return true;
//}
return true;
}
}
And finally, this is how I set up the button click listener:
Button button = FindViewById<Button>(Resource.Id.button1);
button.Click += (s,e) =>
{
//int i = count % s.Count;
//if(i > 28)
// Toast.MakeText(this, button.GetX().ToString(), ToastLength.Short).Show();
button.Text = string.Format("{0}", count++);
};
You have to intercept the touch event. In order to do that you have to subclass LinearLayout and override onInterceptTouchEvent():
public class MyLinearLayout extends LinearLayout {
public MyLinearLayout(Context context) {
super(context);
}
public MyLinearLayout(Context context, #Nullable AttributeSet attrs) {
super(context, attrs);
}
public MyLinearLayout(Context context, #Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
#Override
public boolean onTouchEvent(MotionEvent event) {
Toast.makeText(getContext(), "onTouch", Toast.LENGTH_SHORT).show();
return true;
}
#Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
return true;
}
}
Your xml:
<?xml version="1.0" encoding="utf-8"?>
<com.your.package.MyLinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/LinearLayout1"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:orientation="vertical">
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:orientation="horizontal"
android:layout_weight="1">
<Button
android:id="#+id/button1"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="1"
android:layout_marginBottom="0.0dp"
android:background="#android:color/holo_green_light"
android:soundEffectsEnabled="false" />
<Button
android:id="#+id/button2"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="2"
android:visibility="invisible"
android:background="#android:color/holo_blue_light" />
</LinearLayout>
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_weight="1">
<Button
android:id="#+id/button3"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="3"
android:background="#android:color/holo_red_light" />
<Button
android:id="#+id/button4"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="4"
android:background="#android:color/holo_orange_light" />
</LinearLayout>
</com.your.package.MyLinearLayout>
Now any touch event on the layout will be handled by your custom MyLinearLayout.
You need to extend (inherent) the parent linear layout so that you can intercept touch events from the nested children layouts. Override these two methods to receive touches from the children. Then in your xml you will add "myCustomLinearLayout" or whatever you name the your custom linear layout class. It should be pretty similar in C# / Xamarin.
#Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
return true; // With this i tell my layout to consume all the touch events from its childs
}
#Override
public boolean onTouchEvent(MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
// Log.d(TAG, String.format("ACTION_DOWN | x:%s y:%s",
break;
case MotionEvent.ACTION_MOVE:
//Log.d(TAG, String.format("ACTION_MOVE | x:%s y:%s",
break;
case MotionEvent.ACTION_UP:
break;
}
return true;
}
I am trying to implement a virtual joystick that is sending data through a socket. I want data to be sent only when user is pressing (touching) the joystick. Everything was working fine with the code, but I decided that joystick view should be bigger. To achieve it i changed the android:layout_weight in the leftSide RelativeLayout from 4 to 3. After this adjustment on touch events are never registered. Joystick animation is working perfectly though. Reverting changes make the program work again.
What is happening here? What are the other ways to make view bigger on the screen?
I have the following layout file
<LinearLayout 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"
android:orientation="horizontal"
android:baselineAligned="false"
tools:context="com.my.package.DisplayControlActivity">
<RelativeLayout
android:id="#+id/leftSide"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="3" >
<!-- working fine with android:layout_weight="4" -->
<SurfaceView
android:id="#+id/videoStream"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
</SurfaceView>
</RelativeLayout>
<RelativeLayout
android:id="#+id/rightSide"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical" >
<ImageView
android:id="#+id/testImage"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:contentDescription="#string/test_image"
android:scaleType="fitStart"
android:src="#drawable/test_image" >
</ImageView>
<com.my.package.SquareJoystickView
android:id="#+id/virtual_joystick"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true">
</com.my.package.SquareJoystickView>
</RelativeLayout>
And here is OnTouchListerer part of the code:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
/* some irrelevant code */
joystickView = (SquareJoystickView) findViewById(R.id.virtual_joystick);
isSending = false;
joystickView.setOnTouchListener(new OnTouchListener() {
#Override
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
if (event.getAction() == MotionEvent.ACTION_UP) {
isSending = false;
}
if (event.getAction() == MotionEvent.ACTION_DOWN) {
isSending = true;
}
return true;
}
});
}
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?
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;
}
});