0

I need to make something that allows a user to drag between triangular views, and that will send drag events for each view. However, with all triangular buttons I try to implement, the button calls onclick even when a user taps a point not in the triangle but in its bounding box.

Button xml (to make triangular shape):

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
    <item>
        <rotate
            android:fromDegrees="45"
            android:toDegrees="45"
            android:pivotX="-40%"
            android:pivotY="87%" >
            <shape
                android:shape="rectangle" >
                <stroke android:color="@android:color/transparent"     android:width="10dp"/>
                <solid
                    android:color="@color/red" />
            </shape>
        </rotate>
    </item>
</layer-list>

Button added to MainActivity xml:

 <Button
    android:id="@+id/triangle1"
    android:layout_width="60dp"
    android:layout_height="60dp"
    android:background="@drawable/triangle" />

How could I fix this?

user3404696
  • 121
  • 1
  • 5
  • you may want to do a `Layout within a Layout` trick. The point is, the `Outer Layout` contains the `square like container` of the button, while the `Inner Layout` contains the shape of the button so that it's the only thing that can be clicked. – Scar Mar 21 '16 at 07:17
  • Maybe this could help you: http://stackoverflow.com/questions/35913602/bounds-in-custom-triangle-button/35924090#35924090 – Hoang Nguyen Mar 21 '16 at 07:56
  • Thanks, I tried those. However, it keeps defaulting to square wrappers around the triangular shapes i tried, so it's still using the triangle clicker method when i click outside that area. For some reason, the inner layouts aren't accepting the triangular shape. – user3404696 Mar 21 '16 at 16:47

1 Answers1

0

(This isn't actually an answer - my reputation is just not high enough to comment here ;))

Try this out Android Custom Shape Button it should work with any shape, including triangle

Namnodorel
  • 385
  • 5
  • 17