how to add shapes using java code to a xml layout? - android

As per my requirement I need to add tow rectangles in a existing xml layout through java code. I can create the rectangle shapes using ondraw method, but using intents in fresh layout. I need to display that shapes in existing layout. If any one faces this experience, please help me to create shapes in a xml. Any responce would be appreciated.
Thanks in advance

If the rectangles have a predefined place and size it it only a question of changing the visibility at runtime.
Give the rectangle the attribute android:visibility="gone" in the xml, and from the code use the setVisibility(View.VISIBLE) on the reference to the widget when you want to show it. In this way you may hide it again when no longer needed.
If this answer does not help you please specify more details and I may be able to help you better.
BR,
Vanja

Related

Android : How to draw layout with slanting and curved edges like this?

I am unable to figure out how to design layout in android like the images shown below.
Please suggest some solutions in order to achieve the same.
This can be achieved in two ways:
1- Use images in the background and position them accordingly.
2- Write your own View class and override the onDraw(Canvas canvas) method. You can get help from Android documentation.
Creating Custom Views
Creating a View Class
OR
Check this solution for help:
Android custom shape
As the other answers said, you can create custom views in android.
The curves are called Bézier curves. Similar questions have been asked before.
This question and this tutorial might help you on how to implement the curved view.
You can use SVG wave for background, and you can use this link to make online.

How to style TextViews that look like "cards"?

I want to create an android style that allows me to put TextViews, pictures, and other elements within the "cards" as demonstrated in the link below. I think that design really adds depth and helps separate content from the background and I'd like to use it in my app. However, I don't know how to create that. If you could help that'd be greatly appreciated! :-)
android card design example
Those TextView just have a custom background. This may be
A 9-patch image
A xml-drawable
I suggest reading on 9-patch drawables and on android drawables in general.
The reason why I think it's a 9-patch is that this "card" has a slight drop shadow.
See if this Library helps you
http://www.androidviews.net/2012/12/cardsui/

Draw circle in xml in android

I am trying to display my layout via android xml.
Here's what I want to do:
I have 12 buttons with a animals image like this one: , and the circle is the background.
I do not have any idea related to this, how should I start?
Please give me some suggestion so I can go ahead. What things should I use to do this?
You'd be looking for making a custom view. A good place to start is, as always, android's own development site: http://developer.android.com/training/custom-views/create-view.html
i think you can do this with xml. this need simple mathematic calculation that you can not do in xml.
you most extend View class and create your own View. then you can use it in xml.

How do you rearrange buttons where you want them in Eclipse?

Hey guys I am having trouble with placing my buttons in my XML layout. I already have a background and was just trying to put 3 buttons near the middle and thats where I'm having trouble. I know about center gravity and all that but could you help me? Also, If I made my own buttons can I just import them using the image button thing, or is that not right? Thanks for the help!
PS: Also, there is a big white box around my button. How do I get that to go away?
I posted this answer to your duplicate question, so I'll also post it here. :)
You can rearrange elements of your layout by editing the XML directly or by dragging and dropping in the outline view or the graphical layout view (I find the latter harder to do reliably).
To use your custom views, click on the "Custom & Library Views" button in the graphical layout palette, or just type in the fully qualified class name as the view tag in the XML.
If you use Image button you can set your custom Image to src property or background property. If youi chose src you should add android:background="#null".
But I would recommend to use background property while if you use 9-patch png (who knows maybe tomorow you will use 9-patch) they would not stretch if you set it in src.

Android: Need help setting view alignment in code

I basically want to have several views aligned with each other using a relative layout. I can do so using xml, but unfortunately I can't find any documentation that tells me what methods I need to call to get the same effect in code (All the examples and things just use xml). Since the imageviews are being made dynamically xml isn't an option for what I want to do. I've looked at layoutparameters which seems to let me change some options, but I'm not seeing a method that will let me change alignment relative to another view. Any help is appreciated.
After playing around with it some more found that addRule is the method I need. Couldn't find it because I was looking for something with the term alignment in it.
Check out setLayoutParams in the Android documentation:
https://developer.android.com/reference/android/view/View.html#setLayoutParams(android.view.ViewGroup.LayoutParams)

Categories

Resources