Do I need to use layouts when developing games on Android? - android

I'm new in Android development and I have been making a tutorial for a game example which tells that using a layout file is not necessary because of the flexibility need on game development. However I've seen on Android docs that using a layout file is always the best way for Android development.
I'm sorry if my doubt looks obvious or kind of weird, but I'm really newbie and I'd really appreciate if you guys give me some help.

Most Android Games will use a Surface, Canvas, or GL Surface view to render all content to the screen. This element is likely to be fullscreen as well.
And so all drawing of UI and buttons and game elements are drawn directy to the surface, bypassing the use of Android's many UI views.
There is no reason you game cannot use android UI views in addition to using a surface for drawing the game action itself.
And of course you will likely use layouts as well when integrating things such as Admob ads or user dialogs within you game. So in practice you will use both.
But a standard utility application built in android will use layouts almost exclusively.
As a final aside, it is not necessary to use layouts. Every view type can be created either through XML layouts and inflating the views, or by instantiating a view in java code. the main reason for using layout files is because they are fast to build easy to use for a large category of interface design. But he choice to use them or not is your own.

A layout is used for arranging views. If you're not using any views (i.e. you do all the drawing yourself), then there's no point in using a layout.

For game development you are better off not using a layout file. The tutorial you are following is right. You will probably want to draw directly to a GL Surface View.
Personally, I forgo a lot of the features of the Android framework when doing game development. I use one Activity to bootstrap the game and get it running, and I draw to one GLSurfaceView. A lot of Android game dev tutorials follow this approach, and so are probably going to be a lot more useful to you than tutorials for more traditional Android apps.

Related

Which Framework can be used to draw a complex, interactive UI hierarchy on Android? (Like CoreAnimation on iOS)

I'm porting a vector graphics editor from iOS to Android. The app must draw a complex hierarchy of graphical objects in an efficient manner, so that the graphics can be edited with gestures in real time. The edited work commonly consists of images, text and graphical primitives (lines, circles etc.). UI elements like selection highlights are rendered on a separate layer on the top.
On the iOS app, if one component of the graphic changes (for example a small text element changes its content), only that text element is re-rendered.
On iOS, we use CALayer objects from the CoreAnimation framework. This works very well. What framework can be used on Android for this use case? Is there an established "native" way to do that, or are usually third party frameworks used?
Android does not have similar thing out of the box. We do have core.animation but it is limited to simple behavioral animations. To create what you want you need to use SurfaceView or GLSurfaceView and help of clean OpenGL. You may also try to use ordinary Canvas of View - you will have limited possibilities though.
Also there are wrapper around OpenGl and SurfaceView like libgdx it is used mostly for games though - so it has much wider possibilities than you need, but it is less complicated than OpenGl.
Hope it helps.

Making game using image views and layout (not canvas)

I have am developing a game in which most of the sprites are static (but animated). I found that using an imageview with drawable background (using xml) is giving me what I want. I may move those sprites based on user touches and have basic collision detection.
When I search the internet about the game development, most sites talk about either game engine or at least canvas/surface view. However in my case, I find deal with the normal android views and layout is enough to get me to going.
Is making a game using layout, image views and views something that is frown up? am I going on the wrong path with this?
Thanks
It all depends on the kind of game you want to make. If you are making a grid based game, ImageViews could be more useful. However, almost no one makes Android games using layouts. Most people choose to use SurfaceView because it allows much more to be done, and in my opinion if you choose to learn it you will make much better games.
Of course, this is all opinion but I know nobody who creates games using the layout editor.

Android app with libgdx component

I am looking for the best way to develop an Android app that has one component that allows the user to draw shapes, rotate them, scale them, slice them etc. (I am calling this component ActivityArea). In addition to this ActivityArea there need to be regular buttons, textViews, editViews etc. on the app.
I have explored 2 options - using libgdx and building a custom view. Both approaches appear doable. However, with libgdx, as far as I understand, all the buttons, textViews etc will also have to be created using the libgdx libraries. With this regard I have the following questions:
Is my understanding that libgdx will necessarily have to be used to render buttons and other regular android views?
Is there any way of including a libgdx powered view within an android layout?
Are there other libraries/options available that can be used to get geometric functions within an Android app?
Any help is greatly appreciated.
You can use Android UI atop LibGDX if you like. Typically for this you'd use the AndroidApplication.initializeForView(...) method to create the libgdx view and inject it into your layout.
As far as other libraries, if you doing 2d shapes and don't have to have a consistent 60fps, I'd probably just use Android's Canvas.

Building User Interface in Android - Views vs. XML

I am very new to Android development and, while I get the general premise (and have even built a small application), I have been looking at other developer's source code to get an idea of how to better approach my development for larger projects.
One developer's code is read is basically using both XML layouts and Views for the various parts to the UI (similar to what is being asked in this question). I understand what he is doing, but it seems overly complicated to me. The XML layouts provide functionality already to create responses to actions. (For example, "onClick" is provided for most components in the XML.) Layouts can be generated very easily with the XML.
So, my question is - can I get away with building my entire application using just Activities and XML layouts? Can I choose not to use any Views? (Of course, this is assuming a relatively simple app - think task list or something similar.) Or, am I trying to simplify too much?
The general strategy I use is to push as much as possible into XML. It's a very different way of thinking from some other UI development systems, but it's very cool once you get past the learning curve.
I don't know what you mean by choosing "not to use any Views". Every UI component is a View of some sort. If you mean not using any custom View subclasses, then yes, it is definitely possible. The only reason to create your own custom View classes (and then use them in XML!) is when the stock widgets and views don't do what you want. Since they are quite flexible, this tends to be fairly uncommon (until you start getting into fancy behavior or need custom graphics behavior).
There are two ways for Creating UI for Android Application. They are
Using XML - You can use xml for designing UI targeted for supporting Multiple device. Also XML helps you to create Static components.
Java Code -Generally it's not a good practice to creating UI in java. Its suitable, if you creating a samll application. Its also useful when you want to develop application with dynamic components. If you want to create Dynamic Components in UI, Java code helps you to achieve this.
The Good Approach is to create UI via XML, unless there's no dynamic component needed in the UI. if you need dynamic UI creation then you go custom UI creation i,e., Using Java Code.
Since you are New to Android, i would like you to refer android developer site
I think you misunderstand, XML layouts are just a shortcut for creating views. You end up with the same results at runtime either way. Mix, match, use one or the other, it's up to you.

non-xml Android views

Trying to program a connect4 style game in Android and running into issues with the views. I have worked with Java AWT and am trying to get the same functionality out of Android. A simple drawing system by which I can update the game board and have the screen remain until a button press causes a change to the game board.
I have tried looking at a few tutorials but most tend to go the XML route which I am less familiar with, and also it seems it would be harder to update each of the game board locations using XML.
Any easy to understand tutorials or specific instructions would be really helpful.
Really just looking for a way to specify locations within a view by pixel location since that makes the most sense in my mind. if there are far easier ways those would be appreciated.
All you need is drawing directly on a given canvas. The official site got the resource you need.

Categories

Resources