I am trying to draw 3 lines real time, whose co-ordinates are constantly updating. In this link, How to draw a line in android, it is explained how to draw lines, but they take up all of the screen. How do I get it to take up only part of the screen, and let my layout main file take up the rest. Is this possible?
Thanks,
Rokky
If you wish to dynamically create the DrawView, as your example shows, 1cCreate a view (perhaps a FrameLayout) within your layout xml which will hold your canvas, and use standard Android layout techniques to make the FrameLayout be the right size.
Alternatively you can create the DrawView statically by placing it directly in your layout; How to add CustomView to Layout fromXML? shows how to do that.
Related
I wanna create a custom view with three circle images view using native android. Now I can create one circle image view using CircleImageView from hdodenhof. I wonder if anyone can tell me which way is better to put three circles like the following pic. Thanks.
You could, as you suggest, build a custom view from three CircleImageViews and an appropriate layout.
However, I suspect that you would have difficulty getting the circles to layout in the manner shown in your sample.
I'm fairly certain that this would be next to impossible with RelativeLayout, though you may be able to accomplish this with creative use of one of the other layouts.
Other options include:
Merge the 3 images in a graphics editor, and then create a custom view using that.
Merge the 3 images as above, and just use it in an ImageView
Create a custom view from a Canvas, and draw the images yourself, at the appropriate locations.
Which you do will probably depend on how you want the custom control to behave, including:
is any part of it to be animated?
are the 3 circles to be separately clickable?
I have created a relative layout with couple of buttons at the bottom of the screen. The reast of the screen is blank. I want to place/drag images where user touches the screen. I am between 2 options. These images have animation so I was going to use animationdrawable
1- Use the activity OnTouchEvent to make sure the click is within empty area and start placing/moving images around
2- Create a surfaceview in this area and implements its touch events and deal with a surface view.
What do you think?
Thank you
Well, both of those ways should work and i think it is optional choise.
Here i think i would go on the onTouchListener because that all of your view is writen with xml, using surfaceView now will make the code complicate.
I think you should take it aldo because it is writen for you. This will make your life way easier.
You are using drawable, stored as integer in R and making surfaceView will be difficult because you will need to use the SurfaceView, bitmaps inside him and the xml.
To get the press you will use onThouchListiner anyway, stleast when you do it, you will make your life way easier
The blue rectangle in which test is written, how it is covering ,one full and some portion of lower and upper cell?, ,,, how these cells are made? , this isnt a simple grid. consider this ,what this layout contains, how blue rectangle can cover a specified area.?
help out
This is probably a custom view.
The background texture is a Bitmap , the cells are line drawn on a canvas and the blue area with text is a drawn rectangle.
When you create the view , you know oh many pixel represent an hour , so you should be able to give an exact position to the rectangle.
At least it's how i would do it.
You should have look at Creating Custom Views in android resources and more specificaly read Custom Drawing
To create such view you can:
create your custom view and draw on its canvas
use GridLayout that's available as a support library for android 2.1
I suggest to use the second variant.
i am trying to create the following UI in android app
In the above image all the five are to be image buttons. How to design this UI as like in the screen shot please help me friends....
Inside LinearLayout take RelativeLayout and make it centrally aligned.Then
Take first image Near me and set it's property.
Now take the second image Explore and set it to right of first image.
Place third image My network and place it below first image.
Fourth image Live set this to right of third image and and below second image.
Now center aligned your center image.
You will need to create 5 images, each of which has transparent areas. This layout type lets you position elements relative to the layout group itself, as well as to items within the group.
I'm not very familiar with Android advanced layout design, but the common layout objects give an idea:
There is a SurfaceView which gives you the ability to manipulate z-coördinates. In the SurfaceView you can then place a Grid/Relative/TableLayout for the 4 buttons (which you pre-render as rectangular images with transparency) and a simple Layout which centers and only contains the middle button.
If you then set the Z value of the first layout to less than that of the second you will get the view you want.
I want to make application which will have background and some picture with alpha channel in front. Between them i want to draw bitmap/animation.
How can i do it ?
That is easy. You can use FrameLayout as the root layout and set a background to it. Then add two more LinearLayouts which fill the screen. In the first you may add your animated views like ImageView, while in the second you can insert an ImageView or ImageButton with a transparent image in it.
There are many other ways to do this like using a custom view for your animated layer etc. Check my example here: How can I use the animation framework inside the canvas?