use two separate spaces in an image as a button in android - android

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

Related

Creating a Button looking like a "L"

I am currently working on an app where the UI is really important. So, I need to create a Button with a particular shape. I'd like to create one so my UI could look like this :
I saw several tutorials about creating your own drawables, but here my problem is the particular shape of my input. The "L" form bothers me ..
Any idea ?
I keep looking for a solution, and if I find one I will post it here as an answer.
You can either use an image of the shape you required or you can use 2 views places horizontally to each other. The first view will contain the yellow color as background with rect footstep image and another view with half of the height of first one having yellow background will be on the right of the first view.
P.S :
You can always use canvas to create your own views.
___________
|.....|.B....|B...|
| G.|____|.....|
|.....|........|.....|
|.....|.G__|.....|
You can't create a view like this BUT you can create a rectangle View like an ImagView that contains drawable like L. All you have to do is use VectorDrawables. create an SVG Image and then Convert it to a VectorDrawable by using Plugins like SVGVectorDrawable.
here is how to add plugin to your AndroidStudio
After All set the drawable to your Views Background.

Custom Button Shape (substract shapes)

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.

How to add multiple coloring pages in basic Android drawing app?

I am completely new here and to developing apps. I following a basic tutorial:
http://code.tutsplus.com/tutorials/android-sdk-create-a-drawing-app-interface-creation--mobile-19021
It has three parts to the tutorial. But eventually you have an app that can draw with multiple colors, can erase, save, change the brush size and start with a new canvas.
My aim is to add an option for the user to choose a background for the canvas. I have already set a drawable to be the background for the canvas currently used. So that the kids can "color in". I now want to add a button which lets that change the background of the canvas. I would like to let them choose between 9 different "templates"
As the app has many different pieces of code, and i dont know exactly which one to paste here, please go to the tutorial page to see all the code that was used. OR just ask me which part to paste in here.
Sorry if I am being unclear or vague, but im really an early beginner.
Thanks so much.
Try overriding the onDraw method of your custom view for coloring in so that, before it draws the background drawable you have assigned, it fills itself with the color the child has selected and then change your drawable so that it is transparent apart from a hollow sketch of the object they are coloring in.
You can also work in layers by separating the background color, the drawable and the childs scribbles in three views on top of each other and combine them only when you come to save the finished work.

Draw a gradient filled polygon to use in a selector

I am trying to create a drawable such as this in Android:
I don't think a nine patch will work because there is nowhere that can safety scale vertically. So next I tried a shape drawable but it does not support triangles.
I want to render this image on the fly so there are no artifacts. Also I want to be able to use it in a selector, so I need to be able to represent this image in xml. Maybe I need to extend some class to manually make the shape. If so how do I embed a tag in the xml to tell it where to render? Does anyone know where to start with this or have an example of something similar?
I have read the first 10 pages of hits on stack overflow and google and am not getting anywhere. Thanks very much for any help.
I think a 9-patch would work. For the vertical stretching on the left boundary, fill in the line from top to bottom.

Irregular shape buttons on the UI of Android app

I am in the process of creating an app which requires irregular shaped buttons. I know that i can use image buttons and have the irregular shapes set as the images but no matter what is the shape of the image, it always occupies a rectangular area on the screen.
Is it possible to have the button occupy the exact shape of the image alone?
Do i need to create a custom control or layout for doing this or is there any other valid approach?
If i need to create a custom layout then how do i ensure that the space enclosed by all the buttons that i have placed on the layout is always circular or elliptic?
I suggest you start custom and try to generalize enough to allow others to use and participate in the development of your: 'anyshape' android ui component(s).
The J2ME platform's ui components took that route some years ago.
In any case, as you might allready know:
http://developer.android.com/guide/topics/ui/custom-components.html

Categories

Resources