Android Canvas layout - android

I was using XML to create layouts for my application but recently I found that layouts can also be created with the help of canvas using surface View so I wanted to know whether it is advisable to create a layout with the help of canvas or not?

You can use Canvas to draw things on it, like lines, circle, text and bitmaps. However you can not add Widgets to it.
So yes, you could use Canvas to create Ui, but you would have to do everything from scratch, basically reimplement needed Widgets. This is what games usually do, but its impractical for "normal" projects, especially if you need complex Widgets like ListView.

Related

Android custom UI for app

Does anybody have any idea on how to approach custom UI for an app?
I mean, there are several amazing looking apps out there, that DO NOT look like they were made using the layouts and views offered by Android.
Such as: PIE UI,
Color in the Dark, or look at this collection Collection
I basically want to know how to draw custom shapes and arrange them while making them clickable.
I know how to draw regular custom shapes, but how do I arrange them how do I make really custom shapes like parts of a circle or an ellipsis or even irregular shapes?
I know a little Photoshop, so there I can draw whatever my imagination lets me, but how do I integrate yhe images/shapes drawn there in the UI since I cannot place a shape by it's coordinates? Not all shapes can be placed inside a rectangle, because some parts might overlap. So how are they doing it?

Draw bitmap to canvas, being the main activity?

I want to draw a bitmap to the canvas.
However, I am an inexperienced programmer and don't know how to make the canvas the main screen.
Basically, I want to draw a bitmap to the main activity using a canvas. I know how to draw bitmaps to canvases but it doesn't show up anywhere that I can see (with only one activity). I want the bitmap to show up on the main activity. Any tips?
Sorry if the wording is confusing, thanks for any help.
see these links. might think they may be helpful.
https://www.linux.com/learn/tutorials/707993-how-to-draw-2d-object-in-android-with-a-canvas
http://www.linux.com/learn/tutorials/703911-2d-drawing-with-android-motion-sensors
you can try searching online..
some example
http://www.edu4java.com/en/androidgame/androidgame2.html
or some game engine which will help you to develop game with proper memory management.
https://stackoverflow.com/questions/17163446/what-is-the-best-2d-game-engine-for-android
What you are trying to do is create your own CustomView. When you are putting a button or anything in your layout file that is actually a view. Android does allow you to create your own view to manually handle things on the screen. Games are usually implemented that way. They use customview by extending SurfaceView/GLSurfaceView.
As for the solution of your problem:
create a custom view by extending the View.
add all the constructor from superclass.
override onDraw method
onDraw method will pass you a canvas for you to draw
draw whatever you like(Bitmap, line ,....) using canvas
In your layout file include the customview you just created.
<my.packagename.MyCustomView android:width .... > </my.packagename.MyCustomView>
Hope this helps.
Also you will find lots good resources on how you can create your own customview.

Is there any way to draw something on top of the root layout in Android?

Is there any way to draw something on the top of my application without extending or rearranging the already existing layout?
Maybe there is a trick i don't know with the Window
Think of it like Samsung's Galaxy Note Pen drawing that allows you to draw on top of existing application
I'm agnostic of the underlying layout. Also i don't want to distort it.
I know that probably there is not so please don't answer that there is not if you are not absolutely certain about it.
It looks like you need to use Canvas and/or Drawables. Look here:
http://developer.android.com/guide/topics/graphics/2d-graphics.html

Android View options - draw to a canvas directly or use views

I'm converting a project that I wrote in AIR a long time ago to native Android. In AIR, positioning views was fairly easy in x,y coordinate systems. With native Android though, I am trying to approach this in a correct way, but I'm unsure how to approach.
My view will consist of two circles in the background, with small objects within those circles that can roll around. There will be another view drawn on top of the circles to make it seem like there is glass over the circle, entrapping the small objects. The small objects are bound to the background circles.
I guess what I'm really asking is canvas drawing the best approach here, or is a view-based layout workable as well?
It sounds like your best option would be to use a SurfaceView. This is basically a hardware accelerated canvas. On of the benefits is that you can overlay standard widgets over top of it if you need to so you can mix and match custom and standard components. Here is a link to a website that walks you through getting a SurfaceView up and running

display transparent view over existing views

In Android 2.2, I want to display a few sprites and clickable animations over an existing view. I just discovered that SurfaceView cannot be transparent
I tried overriding dispatchDraw() of a LinearLayout but that doesn't seem to be callable via a Runnable Thread.
I also tried to extend Canvas directly, but that quickly turned into a mess when trying to place it in my XML layout.
Do I have to use GLSurfaceView to have a drawing view whose background is transparent?
Optimally, I'd like to just have a Canvas on which I can draw Bitmap at various coordinates, instead of dealing with the details of GL (unless GL is the only way I can do transparency).
Silly Rabbit. Just use Views and move them around wherever you want within a FrameLayout. SurfaceView is not designed for what you're trying to do.
I'm going to try Switching from Canvas to OpenGL and toss in parts of TranslucentGLSurfaceView.
I'm still open to selecting an answer that doesn't require OpenGL, just for the sake of it solving my original question.

Categories

Resources