Image comments: Icon should go centered in the red bit. The text should go centered in the yellow bit.
I'm trying to create a button in android that looks pretty much like the above. I tried with the imagebutton, the normal button (with drawabletop and drawablebottom), but the text is not proper aligned then.
Do note that I prefer not to use shapes, as the final result will be ninepatch images (that come from photoshop). Although feel free an example there for documentation use.
Also note that it needs to be clickable.
I think i just need to create a custom XML for this below, and then somehow have a button make use of this. I just haven't figured out how/where i need to set the text and so on then.
Any advice on this is appreciated.
hiii....
While using Button... you can align your text as per your expectations using android:gravity="center"android:text="TestHere"`
Try using this... In my case this works f9... It does or doesn't help you plz let me know
You could create the lower part as a separate button, and the above part as an imageview. In your layout file, place the top part above the bottom part. And finally, in your code, create a on clicklistener and assign the same listener to both the button and the image. Of course this would only cause the bottom part to act like a button(looking like it's pressed), but perhaps that's acceptable.
As you want to use Nine patch, create nine patch such a way that the content area is only in the middle of the yellow portion. I'm sure you know how to select content area for nine patch.
Related
How in Android the buttons with complex shape can be done?
For example, take a look at this joystick
Each button should have several states (default, pressed, etc). It is simple to implement with regular buttons. How it can be done here?
How is it possible to create custom clicking area shape (e.g. arch shape for button "Up") that will be a bit smaller than button shape?
Look at each button individually and use a layout (such as a FrameLayout or RelativeLayout) to try and fit the pieces together. Start by making a ToggleButton and using a drawable background (`android:background="#drawable/button_background") to give it the look of one piece of the button. Do this and align all four buttons in the shape you'd like, then put place another layout behind them (with a background drawable) do complete the final piece, giving the buttons a container that makes it appear as one solid element for users.
I'm not entirely sure how you would work with the touch radius of each button... I suggest you look up other examples that work with 'odd' button shapes to hack together a working solution.
Android Custom Shape Button
I hope this points you in the right direction.
The real solution is to create own view to correctly handle such type of shapes. Custom views discussed here: https://developer.android.com/training/custom-views/index.html - you can also find some other sources on the net.
I've designed some buttons with photoshop but now it came in my mind the problem on how make them work.
Basically I've this image
I've thought about two solutions: the first one is to place them in a RelativeLayout and place them with "lot" of padding/margin work, the second solution is to cut them vertically and attach them one by one, like this:
In the second solution I cannot probably use selector, not on all the button at least, not a big issue btw. With the first one I'm a bit worried about scaling on different screen sizes.
It will be a problem? Which solution would you suggest?
Thanks in advance.
Its not a must that your clickable area should be the same shape as your image shape..
Change the Image onclick...
If your options are open to use an image view instead of button, Then the whole image will be clickable.
I searched all over to find this question similar to yours.. Hope it helps.
Android provides the SlidingDrawer by default looks like below image -
Image http://www.gru.at/android/wp-content/uploads/2010/09/s_open.png
Can we customize this SlidingDrawer looks like semi-circle type with buttons included. For, example take a look at below image -
Anyone done the SlidingDrawer like above one. I've googled it. Didn't get any nice solution for this. Anyone has idea/example blog for this?
So make sure you have Gimp and 9-Patch at the ready for a lot of trial and error...
Then what you wanna do is...
Add suitable layout to hold buttons where the current ImageView Handle is, like Horizontal LinearLayout or RelativeLayout
Cut the id of the current ImageView Handle and add it to this new Layout you just added
add your buttons to the LinearLayout/RelativeLayout (you can test it now, the buttons and the handle should all slide open at the same time)
Now add Button listeners for each of the buttons
Set the SlidingDrawer to android:allowSingleTap = "false" (tit for tat, you cant have the single tap option anymore, just the slide)
Use a ButtonSelector.xml to have different layouts for buttons be pressed or not pressed.
This is the hard part. Edit the drawables for the buttons, and handle so that they will fit together nicely if the screen is huge, small, landscape, portrait. I recommend using 9-Patch in conjunction with Gimp.
Pat yourself on the back because you now have a totally sweet custom sliding drawer.
Make sure you post pictures and state any problems or issues you ran into as I have never fully implemented this, but I did get to step 6 to make sure it was possible.
Last but not least, Good Luck...
Thanks for RelativeLayout and FrameLayout These layouts makes my requirement comportable with what i need. I've done like below steps -
First, i've splitted the full image into three pieces. And, merge these images with FrameLayout And, gave onclickListner to my center of image(Because, it was contain that arrow marks up/down)
And, i've used the Animation for just to open that View as SlidingDrawer
These steps helps me lot.
I need to create some custom buttons as shown in the image below
what is the best approach to follow?
thanks
Abdul Khaliq
That's a hard one. I made a lot of custom views, and the first thing I would thinking of is, made one Button with that above image, and handle onTouch by yourself so you can distinguish which area the user hit. There you can also change the state of the button, like changing the image to a bevel one e.g. when the left button is hit.
Can you imagine this ansatz?
You can place two transparent "invisible" buttons over the top of a background in a LinearView. Like two ImageButtons with a transparent png inside.
It is also possible to make this background animated when buttons are clicked using android animation class.
Is it possible to create a layout based on (background) images? For example, there is well know app called Appie that uses this picture as a homescreen:
I might be able to recreate the layout with a TableLayout, but this will be difficult to get it perfectly aligned with the buttons in the image. The default layout options make it very difficult, or maybe impossible, to allow for selection of the buttons on the image (especially when the buttons are in an arc-path).
Can anyone tell me how this is done?
I had some issues positioning a badge on the corner of a view. You can check my solved question:
Positioning a badge bubble on the left upper side of a button
About how it can be done. I would do it with a RelativeLayout and TableLayout as you mentioned, but to be completely sure, you can use apktool to see how the xml are done but it might be ilegal to do it.