One layout over another at run time? - java

My game app has many complex graphical elements and I am worried that having a banner ad continuously on screen will detract too much from the game. My plan is that the user will be able to play each "level" in the game using the full screen without any ads, but upon completion of each level an ad will slide in, on top of the top part of the screen. Presumably this means I have to somehow create a layout programatically that will appear on top of the existing screen layout. Can this be done? If so how?

It can be done.
Afaik you simply have to create a layout which is android:backgroundcolor="transparent".
Else you could do it so you started a new activity on each level completion?

Related

What is the best layout I should use to meet my requirements in Android App Development about regional advertisements and overlapping Views

I am working on various type of ads that can be implemented to a pre existing streaming app.
The content provider will chose what kind if ads they want to be displayed and it should show on the screen.
I was thinking about making different Image/Text Views for each type of ad and making them overlap and only displaying the ones that are currently being scheduled and and visibility for the ones not currently scheduled is GONE.
Different type of ads are Banner Ads, L - Band Ads (2 images form a l-shaped ad in the bottom left corner of the screen), Scrolling Text Ads etc.
What is the best layout I can use to implement this (some view position are relative to each other like l band other depend on parent like banner is aligned to bottom of the screen)?
If you are keeping other layouts as GONE then using Linear Layout will be good to use. You will be displaying only one layout at a time so there is no need for any special Layout.

Natural approach to create a dynamic game engine for Android

I want to create a simple game engine for Android. I am fairly new to the OS, and I want to be sure that I do not start off in the wrong direction.
My requirements are fairly simple:
The game engine is an application that runs a game that comes as a bundle of media files (images, audio) + one "description" file (e.g. xml or yaml format) that describes and links different "scenes".
A "scene" is just a background image + a background music + different actions that can be triggered with buttons.
Typically, clicking a button moves the game to a different "scene".
The first question I have is: Should I have one or multiple Activity objects to create the scenes? That is: Is it better to have one single activity which content is dynamically updated when clicking the buttons; or to have one activity per scene.
Note that the difficulty is that the game engine has to generate the activities dynamically. So the list of buttons cannot be hard-coded inside a layout file, as they come from the description file. I have found this example that shows how to create a layout dynamically. Would you recommend using the same approach?
Assuming I use a single activity for all scenes, it means that when I switch scene (by clicking a button), I need to fully update the view (background and buttons). To do that, should I rather remove each element one by one with removeView(), or rather create a new blank layout with setContentView(), and then populate it with the new background and buttons?
Any advice is welcome.
Example of scene:
Background image: A bedroom image
Background music: bedroom_music.mp3
Actions:
Leave the room => Go to Living room scene
Leave the room through the window => Go to Garden scene
Pick up alarm clock => Add clock to inventory
Activities are usually used for different "views". For example:
A chat app will have a lobby activity and starts a new activity when opening a chat screen.
Following the analogy above I would say you should use only one activity and load the correct scene in that activity. There could be an activity controlling these changes? Or an activity that shows a layout while loading.
Having said that. I think you have to design custom objects that can be converted to buttons/walls/monsters or such. This will make the dynamically loading of buttons/objects easier. In Android you must define buttons/visual objects in a layout xml file. This file will be loaded by an activity. I don't think these xml files can be modified on the fly.

How to create a custom android button overlay?

So to expand on the question stated, to my best understanding android apps have a set of activities such as the default activity_main.xml and you could even generate a login screen (activity_login.xml). After fiddling around with it I sort of feel comfortable with the way buttons work, yadda yadda, but my problem emerges when I want to create a game activity. I am not concerned about that part, I would just make another activity (activity_gameplay.xml) that I would run the game on. My problem is that I want to render my own custom buttons onto the screen which would be transparent and would be stationary while the actual game environment would be moving. Such as in Minecraft(android version obviously).
So to conclude I need to know how to render custom buttons, and though not included in the above, how to position the buttons accordingly sense the XML way only allows stuff such as upper left-hand corner etc.

How to develop a walk through dialog that appears on the first launch?

I would like to develop a Dialog which is composed of 3 steps to guide the user when he launches the app for the first time.
The following image is an example of what I would like to achieve:
1- I would like to know how to add a mark to close the dialog at the top-right corner?
2- How can I implement the small circles at the bottom of the screen that indicates the current step? Can they be created programmatically?
3-Only to be sure, I decided to navigate between the Dialog steps using a ViewFlipper. Is this the right approach?
Thanks in advance.
I would like to know how to add a mark to close the dialog at the
upper right corner?
Don't do that. That looks like it was a straight port from an iphone app. Use the native android dialog containers/buttons.
How can I implement the small dots at the bottom of the screen that
indicates the current step?
What have you tried? There's a million ways of doing this depending on the rest of the workflow.
Only to be sure, I decided to navigate between the dialog steps using
a ViewFlipper. Is this the right approach?
Maybe. It depends what you're displaying. If you're only displaying a single image or something simple, then that might be the best approach. I would create different dialog fragments ( you are using fragments, right?) for the different steps. That way you can automatically push them to the back stack as you move through the workflow.
one of the ways to implement the "little dots on the bottom" is :
include the dots in every image you are creating.
draw one of the dots highlighted in every image
flip through the images in order of the highlighted dots. (or highlight the dots in the order you want to show your images)
but this would make your dots disappear during the images are flipped.
if you want to avoid that :
create two different image views , one acts as a container for the main image, the other as a container for the dots, place the 1st image view above the other.
create a no of images containing just a no of dots, each with one of the dots highlighted
flip through both the imageViews in synchronization
use a "flip animation" in the upper image view
use no animation, or a minimal animation for the dots.
This will produce the desired effect. Hope this helps :-)

is multiple activities and surface views the correct way to go?

I'm currently in the process of making one of my first android games and have come into some difficulty understanding how to make the transitions between screens.. for example:
My game starts its main activity, which then loads TitleScreen surface view which initializes its own thread
on tap I start a new intent which loads a new activity which loads GameView surface view which initializes its own thread
This all works fine when testing on my device (Evo 3d) but crashes on tap on my test bed, I'm using android x86 in virtual box for quick testing. Is this likely to be a problem in my code or a problem with the simulator?
Also I'm wanting to add a level select screen in between the title screen and the game screen and figured i could do this by creating another activity/surface view/thread combo, Is this acceptable coding practice or is this a wasteful/process heavy method?
You could create a variety of methods that you call from your onDraw method. Each method would draw one screen (game, level, score). To start simple a switch case in the onDraw checks the screen and then calls the right thing to draw.
If you want to have different layers, you should use different acitvities so that the background (game) is being paused while the scoreboard is active. This only makes sense if you want the background to be still visible or need the acitivites for other reasons.
But you should never have more than one surface view active at the same time, android doesnt like that.
I think its not good to use more activities for single application. Try to use ViewFlipper with number of xml layout files. Here you can apply transition effects very easily.
I am suggesting you it for transition effects, but you also check it once. I am also thinking which one is good.

Categories

Resources