I try to create a custom button where a circular shape is cut out from a rectangular button, see mockup.
I already looked into the Outline class but it doesn't provide subtraction, only rects and ovals, no combination of them.
Also, I thought of setting android:background to a custom drawable but I couldn't succeed. The drawable consisted of a layer-list with a colored rect and a white oval but the oval was always placed at a different position depending on the device's resolution.
Do I really have to go through the pain of creating my own View class? That seems to be an overkill for this rather simple task, doesn't it?
PS: Concerning usability, I know that buttons close to each other aren't user-friendly, but this problem doesn't arise in my real scenario, only in this mockup.
Related
There is the concept of rounded corners for views and drawables in Android, however, am working on an interface for a kids robot, and someone asked for curly borders - sort of like wavy (sine wave kind of thing). Now, how the heck can one achieve such a thing in either XML or Java - especially, without resorting to use of image overlays or backgrounds?
rounded corners aren't in fact rounded Views, its just a bit of transparency in corners. you can create some custom drawables/Bitmaps and set for your Views (as a background or use ImageView) or you can use custom programmatic drawing like HERE
Have tried to use images of that form and use them as background in a transparent container?
Is there any solutions for this problem :
I want these two shapes with blue and pink colors to be separate buttons so whenever the pink space is clicked something happened and the same for the blue space.
PS: i can slice the two portions and create an ImageButton for each but the problem is the button doesn't take the same shape of a portion it is always rectangular so i can't place the other button next to it
I'd suppose to recommend you to write a custom View, that draw this picture itself, depending on some kind of formulae.
Or use an old method of game development when you define color of pixel that was touched or focused.
Define color of pixel touched
PS: i can slice the two portions and create an ImageButton for each but the problem is they don't fit good on the activity
Try to use 9 patch resources or svg drawables instead.
If they are defined well it should work.
Then you will have to write you're own custom button the uses them.
You can read more about it here:
http://www.vogella.com/tutorials/AndroidDrawables/article.html#9-patch-drawables
http://www.vogella.com/tutorials/AndroidDrawables/article.html#vector-drawables
I'll need to implement a UI that reflects the layout of a real object. Below is the layout that the client wants. Each black block is a button, so it need a custom drawable, listeners, states, etc.
I'd like to use a custom implementation of the Button widget, but as far as I know they only accept rectangular touch targets and laying them out could be tricky.
What would you use to achieve this layout?
Please note: the 2 central button should be a semicircle cutted in half (with some padding between the 2), not this strange shieldy shape, I'm just not that good with Photoshop.
EDIT: As suggested in this question I could use a TouchListener on the layout and fake a click on the right button. The main problem with this solution is that I'll need to know the bounds of the drawable, not the rectangular ones of the button's bounding box (that is always rectangular). How could I do that?
Basically What I'd like to try is to have all of my content in an image. I looked up some stuff but what they do is always use an imageView and text. But I'd like to use it as a background image.
Can someone give me an example how this exactly works? And how will the support be for using this with different screensizes, because the content always has to stay in the image?
To clarify what I want, I added an image. The green space is a background drawn in android xml, the white is the actually image and the text should be all of my content. I'd like to keep everything in the white, even if I get more edges.
The easiest way will be to have 3 layers
Top
Mask
Content
Image
Bottom
The mask will be an imageview (in your case only the green parts with the rest transparent).
The base image can be anything, but it would make sense that it complements the masking layer.
The content will be the tricky part. You will need to figure out the bounds of the masking layer so you won't go under the mask. I would suggest centering the content.
Alternatively, if the shape will change in size or is complex I would suggest using a canvas with a clipping pattern. On Android how do I make oddly shaped clipping areas?
In my app I have something similar in appearance to labels in GMail app UI. For those who may not know, they look like this (labels are these colorful bars):
In order to achieve similar effect I use nine-patch drawables - for each label I am creating a TextView and assign drawable to it. This is simple solution, but I don't like it. It's not elegant, it is quite slow as shown by profiler, and I just don't think it's the right way to do it.
I changed the design of the UI to make it more "ICS-y", so I removed rounded corners from the labels. And I started thinking how I could replace 9-patch solution. The most obvious thing is to use BackgroundColorSpan. But it has one, small drawback. I want my labels to have some padding. With drawables, it was easy to achieve. With spans, it's harder. To make horizontal padding, I can just add spaces at the beginning and at the end of the string. But how to make vertical padding larger? To clear things up, this is a screenshot of the label with BackgroundColorSpan:
I want to make the colored parts above and below the text larger. I think I should use some kind of MetricAffectingSpan, but I couldn't figure out which one. Or maybe I should write my own? Or, finally, maybe spans are just not able to fulfill my needs and I should stay with images or create a canvas and "manually" draw everything as in GMail app?
The easiest way to do this, and im pretty sure the GMAIL app is making use of it, are shapes.
Just create a custom shape, in your case a rectangle shape with rounded corners and a solid color, and assign this drawable then to the background property of your textview.
A shape is defined in xml.
You will assign it as follows:
<TextView
...
android:background="#drawable/my_awesome_shape" />