Android Hexagon shape button having hexagon touch bounds - android

I want to create a hexagon shape button in android so that it's touch area does not overlaps (on the right) ie.I want heaxagon touch bound not a rectangle touch bound. I tried to use image view but it does not excludes tranparent(shown in blue, left). Is there any clickable object which is defined by xml shape/path. please can anyone show me xml shape/path part for just one button if its possible or any other method.

check out this
<com.github.siyamed.shapeimageview.{ClassName}
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="8dp"
android:src="#drawable/neo"
app:siBorderWidth="8dp"
app:siBorderColor="#color/darkgray"/>
Attributes:
siBorderColor border color
siBorderWidth border width in dp
siBorderAlpha alpha value of the border between 0.0-1.0
siStrokeCap border stroke cap type butt|round|square
siStrokeJoin border stroke join type bevel|miter|round
siSquare set width and height to the minimum of the given values
true|false
siShape a reference to an SVG. This is used by ShapeImageView, not
the subclasses of it.

There's no system view that would do custom shapes for you. You need to create custom view: http://developer.android.com/training/custom-views/index.html and in its onTouchEvent() determine if user's tap is inside or outside clickable area and act accordingly.

Related

Find radius of background circle drawable

I want to have 3 TextViews that are surrounded with circles as below:
The text views are centered in the circles.
I was planning on using TextView's with backgrounds set to a drawable containing a circle.
However, to position the circle properly I need the radius of each circle.
I tried to use Drawable.GetBounds() and then find the hypotenuse of the boundary rectangle, but this doesn't yield the values I want.
How do I find the radius. Or is there a better way to go about this in general?
Am I stuck just using a custom View and overriding onDraw?
This was a really dumb question. The radius is set to whatever the width or height of the View is.

Setting border color of some part of View

I want to paint Fragment View border's left but not whole border. I want to use left buttons as tabs. When clicked on one of them, I want to paint whole borders of button but right and paint view's left corner except button's right side which clicked on.
Is there any way to do this?
You can create a nine-patch image that has only the left boarder and apply it as the background of the fragment.
more information on how to create a nine-patch image could be found here:
http://radleymarx.com/blog/simple-guide-to-9-patch/
and here:
http://android9patch.blogspot.co.il/

Setting the button radius programmatically in android

I have a button say myButton. I want to set the top left corner radius of the button programmatically.
I'm looking for something like
myButton.setTopLeftCornerRadius(10);
I have looked for a method like 'setcornerradius' in eclipse but got nothing.
You can use shape drawable for this or rounded corner background Image.
For shape drawable detail please see this post.
How to set corner radiuses for the button in java code?
Cheers.
Button is type of View and all Views in Android occupy rectangular areas. However, you can set the background of the button to any image you like. Like a Shape Drawable with round corners.
Try this code for draw the rounded corners edittext:
How to create EditText with rounded corners?

How to align the text with its compound drawables in TextView?

I can't figure out how to set the alignment of text and its compound drawable (smaller than text) in a TextView. It seems the default alignment is center, but I need to align them by the edge.
PS: The android:gravity works great if compound drawable is larger than text, but not if smaller.
It sounds like you're using an image with fixed dimensions for android:drawableLeft.
Try using a nine-patch or defining a drawable through an XML resource file. In this way your drawable's dimensions will stretch to align in the TextView the way that you want it to.
I had a similar problem in that I wanted to use setCompoundDrawables to set a top drawable for a floating hint, however TextView (EditText) sets the top drawable to center, irrespective of what its width is.
I am using a custom Drawable, and inside its draw method, I am grabbing the clipBounds, and translating on its top,left to get back to the TextView's 0,0 position.
The other way to do it easily is to getMatrix and mapPoints from 0,0 then take the negative of them and translate back to 0,0 that way.

How to set absolute (not %) position for the center of a shape drawable gradient?

I've got a shape drawable with a radial gradient inside it. The shape is a rectangle, and I'm trying to position the center of the radial gradient near the bottom right corner. I can get it in the general vicinity using the centerX and centerY attributes set to values like 0.98, but I'm dealing with rectangles of different heights (same width), so the taller the rectangle is, the higher the center position is, relative to the bottom right corner.
It seems I can only position the center as a percentage of the view width/height, contrary to the documentation. That is, even without the "%" in the value, it is treated as a percentage.
What I'd like to do is somehow say "put the center 5dp up and to the left of the bottom right corner". Any ideas on how to accomplish that?
You might try use a Layer-List, there you can specify margins of overlaying layer items, which can be drawables.

Categories

Resources