How to set canvas (paint view) on top of listview and still have listview clickable?
I have a layout that contains a ListView and a few buttons in a RelativeLayout. I am trying to let the user draw on the page using a custom paint view layout. The good news is that I've got nearly everything working and looking how it should, however the last and most frustrating issue is that the ListView is no longer clickable at all. I would like to paint on top of the the ListView AND make it clickable.
The funny part is that the buttons on the page are still clickable, just the items in the ListView are not. I think what is happening is that the ListView is loaded by an adapter and gets loaded first (thus behind everything). What do I need to do in order to make the ListView clickable?
I've tried adding android:focusableInTouchMode="true" android:focusable="true" but it made no difference.
My layout is as follows:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/background"
android:orientation="vertical" >
<ListView android:id="@+id/lv"
android:layout_height="match_parent"
android:layout_width="match_parent"
></ListView>
<com.my.app.PaintView
android:id="@+id/paintView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<Button
Buttons Here.../>
</RelativeLayout>
android listview
add a comment |
I have a layout that contains a ListView and a few buttons in a RelativeLayout. I am trying to let the user draw on the page using a custom paint view layout. The good news is that I've got nearly everything working and looking how it should, however the last and most frustrating issue is that the ListView is no longer clickable at all. I would like to paint on top of the the ListView AND make it clickable.
The funny part is that the buttons on the page are still clickable, just the items in the ListView are not. I think what is happening is that the ListView is loaded by an adapter and gets loaded first (thus behind everything). What do I need to do in order to make the ListView clickable?
I've tried adding android:focusableInTouchMode="true" android:focusable="true" but it made no difference.
My layout is as follows:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/background"
android:orientation="vertical" >
<ListView android:id="@+id/lv"
android:layout_height="match_parent"
android:layout_width="match_parent"
></ListView>
<com.my.app.PaintView
android:id="@+id/paintView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<Button
Buttons Here.../>
</RelativeLayout>
android listview
add a comment |
I have a layout that contains a ListView and a few buttons in a RelativeLayout. I am trying to let the user draw on the page using a custom paint view layout. The good news is that I've got nearly everything working and looking how it should, however the last and most frustrating issue is that the ListView is no longer clickable at all. I would like to paint on top of the the ListView AND make it clickable.
The funny part is that the buttons on the page are still clickable, just the items in the ListView are not. I think what is happening is that the ListView is loaded by an adapter and gets loaded first (thus behind everything). What do I need to do in order to make the ListView clickable?
I've tried adding android:focusableInTouchMode="true" android:focusable="true" but it made no difference.
My layout is as follows:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/background"
android:orientation="vertical" >
<ListView android:id="@+id/lv"
android:layout_height="match_parent"
android:layout_width="match_parent"
></ListView>
<com.my.app.PaintView
android:id="@+id/paintView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<Button
Buttons Here.../>
</RelativeLayout>
android listview
I have a layout that contains a ListView and a few buttons in a RelativeLayout. I am trying to let the user draw on the page using a custom paint view layout. The good news is that I've got nearly everything working and looking how it should, however the last and most frustrating issue is that the ListView is no longer clickable at all. I would like to paint on top of the the ListView AND make it clickable.
The funny part is that the buttons on the page are still clickable, just the items in the ListView are not. I think what is happening is that the ListView is loaded by an adapter and gets loaded first (thus behind everything). What do I need to do in order to make the ListView clickable?
I've tried adding android:focusableInTouchMode="true" android:focusable="true" but it made no difference.
My layout is as follows:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/background"
android:orientation="vertical" >
<ListView android:id="@+id/lv"
android:layout_height="match_parent"
android:layout_width="match_parent"
></ListView>
<com.my.app.PaintView
android:id="@+id/paintView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<Button
Buttons Here.../>
</RelativeLayout>
android listview
android listview
asked Nov 14 '18 at 20:23
stevensteven
147314
147314
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
The focusable
attribute should be false
for the element you do not want to receive touch events. To overlay your PaintView
without having it intercept touch events, you can add a few XML attributes to it:
<com.my.app.PaintView
...
android:focusable="false"
android:clickable="false" />
As long as you don't set an OnClickListener
or an OnTouchListener
to your PaintView, touch events should simply pass through it to the Views behind it.
The PaintView does have an onTouchEvent, it is needed so that it actually draws the line on top of the view (this is a drawing app).
– steven
Nov 14 '18 at 20:56
Then, unfortunately, the only way for you to do this is to manually handle your PaintView'sonTouch
events andreturn false
when theMotionEvent.ACTION_DOWN
should not be handled (causing the PaintView to longer receive the touch events until another ACTION_DOWN on the View is triggered), thus passing the event to the Views behind it. It could be something as simple as a storing a class-levelboolean paintDrawingAllowed
and checking against it insideonTouch
, or a bit more complex like ensuring the touch position is within valid Rects for drawing, etc.
– Cruceo
Nov 14 '18 at 21:08
Thanks for the advice, but didn't work for me because the touch didn't want to work on the listview and canvas at same time. It was one or the other. Managed to find my own solution, will post soon.
– steven
Nov 15 '18 at 4:01
add a comment |
Managed to find a solution that works perfectly (at least for me). I imagine without the listview this would have been far easier, but I wanted the listview to work as well as drawing on the canvas. All I ended up having to do was set an onTouchListener in the main activity that had the ListView, then send it to the PaintView with the MotionEvent. Simple and it works perfectly:
listview.setOnTouchListener(new View.OnTouchListener()
@Override
public boolean onTouch(View view, MotionEvent motionEvent)
paintView.onTouchEvent(motionEvent);
return false;
);
In this example, the paintView.onTouchEvent could really be any method in the custom view, just kept it at "onTouchEvent" for simplicity.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53308208%2fhow-to-set-canvas-paint-view-on-top-of-listview-and-still-have-listview-clicka%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
The focusable
attribute should be false
for the element you do not want to receive touch events. To overlay your PaintView
without having it intercept touch events, you can add a few XML attributes to it:
<com.my.app.PaintView
...
android:focusable="false"
android:clickable="false" />
As long as you don't set an OnClickListener
or an OnTouchListener
to your PaintView, touch events should simply pass through it to the Views behind it.
The PaintView does have an onTouchEvent, it is needed so that it actually draws the line on top of the view (this is a drawing app).
– steven
Nov 14 '18 at 20:56
Then, unfortunately, the only way for you to do this is to manually handle your PaintView'sonTouch
events andreturn false
when theMotionEvent.ACTION_DOWN
should not be handled (causing the PaintView to longer receive the touch events until another ACTION_DOWN on the View is triggered), thus passing the event to the Views behind it. It could be something as simple as a storing a class-levelboolean paintDrawingAllowed
and checking against it insideonTouch
, or a bit more complex like ensuring the touch position is within valid Rects for drawing, etc.
– Cruceo
Nov 14 '18 at 21:08
Thanks for the advice, but didn't work for me because the touch didn't want to work on the listview and canvas at same time. It was one or the other. Managed to find my own solution, will post soon.
– steven
Nov 15 '18 at 4:01
add a comment |
The focusable
attribute should be false
for the element you do not want to receive touch events. To overlay your PaintView
without having it intercept touch events, you can add a few XML attributes to it:
<com.my.app.PaintView
...
android:focusable="false"
android:clickable="false" />
As long as you don't set an OnClickListener
or an OnTouchListener
to your PaintView, touch events should simply pass through it to the Views behind it.
The PaintView does have an onTouchEvent, it is needed so that it actually draws the line on top of the view (this is a drawing app).
– steven
Nov 14 '18 at 20:56
Then, unfortunately, the only way for you to do this is to manually handle your PaintView'sonTouch
events andreturn false
when theMotionEvent.ACTION_DOWN
should not be handled (causing the PaintView to longer receive the touch events until another ACTION_DOWN on the View is triggered), thus passing the event to the Views behind it. It could be something as simple as a storing a class-levelboolean paintDrawingAllowed
and checking against it insideonTouch
, or a bit more complex like ensuring the touch position is within valid Rects for drawing, etc.
– Cruceo
Nov 14 '18 at 21:08
Thanks for the advice, but didn't work for me because the touch didn't want to work on the listview and canvas at same time. It was one or the other. Managed to find my own solution, will post soon.
– steven
Nov 15 '18 at 4:01
add a comment |
The focusable
attribute should be false
for the element you do not want to receive touch events. To overlay your PaintView
without having it intercept touch events, you can add a few XML attributes to it:
<com.my.app.PaintView
...
android:focusable="false"
android:clickable="false" />
As long as you don't set an OnClickListener
or an OnTouchListener
to your PaintView, touch events should simply pass through it to the Views behind it.
The focusable
attribute should be false
for the element you do not want to receive touch events. To overlay your PaintView
without having it intercept touch events, you can add a few XML attributes to it:
<com.my.app.PaintView
...
android:focusable="false"
android:clickable="false" />
As long as you don't set an OnClickListener
or an OnTouchListener
to your PaintView, touch events should simply pass through it to the Views behind it.
answered Nov 14 '18 at 20:49
CruceoCruceo
5,89812041
5,89812041
The PaintView does have an onTouchEvent, it is needed so that it actually draws the line on top of the view (this is a drawing app).
– steven
Nov 14 '18 at 20:56
Then, unfortunately, the only way for you to do this is to manually handle your PaintView'sonTouch
events andreturn false
when theMotionEvent.ACTION_DOWN
should not be handled (causing the PaintView to longer receive the touch events until another ACTION_DOWN on the View is triggered), thus passing the event to the Views behind it. It could be something as simple as a storing a class-levelboolean paintDrawingAllowed
and checking against it insideonTouch
, or a bit more complex like ensuring the touch position is within valid Rects for drawing, etc.
– Cruceo
Nov 14 '18 at 21:08
Thanks for the advice, but didn't work for me because the touch didn't want to work on the listview and canvas at same time. It was one or the other. Managed to find my own solution, will post soon.
– steven
Nov 15 '18 at 4:01
add a comment |
The PaintView does have an onTouchEvent, it is needed so that it actually draws the line on top of the view (this is a drawing app).
– steven
Nov 14 '18 at 20:56
Then, unfortunately, the only way for you to do this is to manually handle your PaintView'sonTouch
events andreturn false
when theMotionEvent.ACTION_DOWN
should not be handled (causing the PaintView to longer receive the touch events until another ACTION_DOWN on the View is triggered), thus passing the event to the Views behind it. It could be something as simple as a storing a class-levelboolean paintDrawingAllowed
and checking against it insideonTouch
, or a bit more complex like ensuring the touch position is within valid Rects for drawing, etc.
– Cruceo
Nov 14 '18 at 21:08
Thanks for the advice, but didn't work for me because the touch didn't want to work on the listview and canvas at same time. It was one or the other. Managed to find my own solution, will post soon.
– steven
Nov 15 '18 at 4:01
The PaintView does have an onTouchEvent, it is needed so that it actually draws the line on top of the view (this is a drawing app).
– steven
Nov 14 '18 at 20:56
The PaintView does have an onTouchEvent, it is needed so that it actually draws the line on top of the view (this is a drawing app).
– steven
Nov 14 '18 at 20:56
Then, unfortunately, the only way for you to do this is to manually handle your PaintView's
onTouch
events and return false
when the MotionEvent.ACTION_DOWN
should not be handled (causing the PaintView to longer receive the touch events until another ACTION_DOWN on the View is triggered), thus passing the event to the Views behind it. It could be something as simple as a storing a class-level boolean paintDrawingAllowed
and checking against it inside onTouch
, or a bit more complex like ensuring the touch position is within valid Rects for drawing, etc.– Cruceo
Nov 14 '18 at 21:08
Then, unfortunately, the only way for you to do this is to manually handle your PaintView's
onTouch
events and return false
when the MotionEvent.ACTION_DOWN
should not be handled (causing the PaintView to longer receive the touch events until another ACTION_DOWN on the View is triggered), thus passing the event to the Views behind it. It could be something as simple as a storing a class-level boolean paintDrawingAllowed
and checking against it inside onTouch
, or a bit more complex like ensuring the touch position is within valid Rects for drawing, etc.– Cruceo
Nov 14 '18 at 21:08
Thanks for the advice, but didn't work for me because the touch didn't want to work on the listview and canvas at same time. It was one or the other. Managed to find my own solution, will post soon.
– steven
Nov 15 '18 at 4:01
Thanks for the advice, but didn't work for me because the touch didn't want to work on the listview and canvas at same time. It was one or the other. Managed to find my own solution, will post soon.
– steven
Nov 15 '18 at 4:01
add a comment |
Managed to find a solution that works perfectly (at least for me). I imagine without the listview this would have been far easier, but I wanted the listview to work as well as drawing on the canvas. All I ended up having to do was set an onTouchListener in the main activity that had the ListView, then send it to the PaintView with the MotionEvent. Simple and it works perfectly:
listview.setOnTouchListener(new View.OnTouchListener()
@Override
public boolean onTouch(View view, MotionEvent motionEvent)
paintView.onTouchEvent(motionEvent);
return false;
);
In this example, the paintView.onTouchEvent could really be any method in the custom view, just kept it at "onTouchEvent" for simplicity.
add a comment |
Managed to find a solution that works perfectly (at least for me). I imagine without the listview this would have been far easier, but I wanted the listview to work as well as drawing on the canvas. All I ended up having to do was set an onTouchListener in the main activity that had the ListView, then send it to the PaintView with the MotionEvent. Simple and it works perfectly:
listview.setOnTouchListener(new View.OnTouchListener()
@Override
public boolean onTouch(View view, MotionEvent motionEvent)
paintView.onTouchEvent(motionEvent);
return false;
);
In this example, the paintView.onTouchEvent could really be any method in the custom view, just kept it at "onTouchEvent" for simplicity.
add a comment |
Managed to find a solution that works perfectly (at least for me). I imagine without the listview this would have been far easier, but I wanted the listview to work as well as drawing on the canvas. All I ended up having to do was set an onTouchListener in the main activity that had the ListView, then send it to the PaintView with the MotionEvent. Simple and it works perfectly:
listview.setOnTouchListener(new View.OnTouchListener()
@Override
public boolean onTouch(View view, MotionEvent motionEvent)
paintView.onTouchEvent(motionEvent);
return false;
);
In this example, the paintView.onTouchEvent could really be any method in the custom view, just kept it at "onTouchEvent" for simplicity.
Managed to find a solution that works perfectly (at least for me). I imagine without the listview this would have been far easier, but I wanted the listview to work as well as drawing on the canvas. All I ended up having to do was set an onTouchListener in the main activity that had the ListView, then send it to the PaintView with the MotionEvent. Simple and it works perfectly:
listview.setOnTouchListener(new View.OnTouchListener()
@Override
public boolean onTouch(View view, MotionEvent motionEvent)
paintView.onTouchEvent(motionEvent);
return false;
);
In this example, the paintView.onTouchEvent could really be any method in the custom view, just kept it at "onTouchEvent" for simplicity.
answered Nov 15 '18 at 4:07
stevensteven
147314
147314
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53308208%2fhow-to-set-canvas-paint-view-on-top-of-listview-and-still-have-listview-clicka%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown