Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8280617
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T09:44:34+00:00 2026-06-08T09:44:34+00:00

My parent view is a RelativeLayout, I added a triangle to it extending the

  • 0

My parent view is a RelativeLayout, I added a triangle to it extending the View class. I draw the triangle using canvas and paint. The problem i am facing is that, when i touch on the relative layout, both touch listeners , the relative layout and triangle are being triggered. I just want the triangle to take the exact space as it requires. How can i limit my customview , triangle in this case to take it’s space, rather than occupying the entire parent layout.

Actually my requirement is: i have one relative layout on the layout i am adding some custom views dynamically. those have touch listeners for for dragging points in the triangle,but those are taking full screen of my parent view, because of that i am unable to trigger touch listeners separately for parent and child view’s.

I’ve spent countless hours developing solutions for this problem and I just couldn’t get my head around it. Any help would be greatly appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T09:44:35+00:00Added an answer on June 8, 2026 at 9:44 am

    From what I am gathering you are saying,you have a triangle drawn within a RelativeLayout in a CustomView. The actual View size is FILL_PARENT for both width and height. So the square representing the touchable area of the triangle is the same as the square representing the touchable area of the parent RelativeLayout.

    You would like touch events inside the triangle’s drawn area to be received by the triangle View and anything outside to be received by the parent. It is not possible to define a custom touch area from what I understand.

    That doesn’t stop you manipulating drawing bounds and touch focus to accomplish what you want though.

    How it can be done

    1. Ensure that your CustomView with the triange always receives the touch event. When it receives the touch event, it perform basic maths to figure out if the touch was within your triangle area (you must have your triangle bounds you use to draw your triangle saved as global variables for the CustomView).

    2. Then a simple conditional statement to determine whether to act on and consume or pass the event on (do you even want a TouchEvent on your RelativeLayout to do anything? If not that makes this a lot easier).

    Example code skeleton:

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        boolean inTriangle = false;
        float x = event.getX();
        float y = event.getY();
    
        // This really depends on what behaviour you want, if a drag extends outside the
        // triangle bounds, do you want this to end the touch event? This code could be done
        // more efficiently depending on your choices / needs
    
        // Do maths to figure out if the point is actually inside the triangle. Once again,
        // many solutions and some much easier than others depending on type of triangle
    
        // This flow will only register events in the triangle, and do nothing when outside
        if (event.getAction() == MotionEvent.ACTION_DOWN) {
            if (inTriangle) {
                // Do whatever it is you want to do
    
                return true; // to say you consumed the event if necessary
            } else {
                return false; // parent RelativeLayout should now get touch event
    
        }
    } else if (event.getAction() == MotionEvent.ACTION_MOVE) {
        if (inTriangle) {
            // Do whatever it is you want
    
            return true;
        } else {
            // Do nothing
            return true; // So is stil consumed
        }
    }
    
    return true;
    

    }

    To be honest, the question is way to open-ended / unclear to give anything more specific. But this is how you would accomplish what you asked. Just apply it to your specific scenario.

    Note: I have encountered issues with TouchEvent passing, so if you really do want to pass them to specific places, you may have to investigate toying with View.dispatchTouchEvent() if the order your Touches are being processed becomes an issue.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My app has a view that gets added to activity programmatically using this code:
I'm successfully converting a ViewGroup (RelativeLayout) into Bitmap using a Canvas. However, when the
I am trying to make a scroll view that has a nested relativeLayout view.
In My Application, My XML layout is like this: <RelativeLayout android:layout_width=fill_parent android:layout_height=fill_parent> <View class=com.project.twsbi.FingerPaint$MyView
import android.app.Activity; import android.os.Bundle; import android.view.View; import android.view.ViewGroup.LayoutParams; import android.widget.Button; import android.widget.RelativeLayout; public class
Iam in parent view while clicking the button in the parent view I want
I have a parent view and a partial view, but when it try to
I use panGestureRecognizer to move imageView.. it can work in the parent view of
I have a parent-child view model object structure set up and need to update
Suppose I have a parent.cshtml view with a parentModel, and a child.cshtml view with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.