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.
Related
I have defined my Relative Layout using the drag and drop tool in Eclipse, so all of my buttons are laid out how I wish. My issue is when I set the onClick listener, that calls a method in another class. So to be able to redraw items on screen, I need to access the layout manager so I can add and remove buttons from the screen as well as update textViews. I have done all of this in a demo I made in Java, and I used a JPanel with GridBagConstraints. Now that I am moving to Android, a system I haven't done much development in, I am at the point where I have to learn some new stuff. For example in my demo I made I could do this:
grid.remove(trueButton);
grid.add(falseButton);
grid.remove(textField);
grid.add(backButton);
Essentially I want to be able to do the same sort of thing in my Android app. If you guys need more info I can provide, I wasn't really sure how much would be needed since I am looking at really just where to start. Everything has been declared in the XML since the drag and drop part of Eclipse does that all for me. It is just the Java part that is giving me some issue.
Why not just setVisibility of the buttons you wish to hide/show? Same with the TextViews.
You can set visibility to 'GONE' and it will be as if the view has been removed (taking up no space in the layout and not responding to touch events.).
I have a 2.5D isometric game that I would like to add a interactive HUD to. I tried using JButtons with Icons but could not draw both the button and my game at once. I'm looking for a cost-efficient (computer resources-wise) technique in which I can draw my own images/buttons to the screen on top of my game.
Most likely will require you to create your own.
First you will need a method of capturing the click event (You may be able to use Swing's existing one depending on your engine). You could for example register a single click event on the screen itself and then implement a method of "capturing" that event through to the component which was clicked on.
Next you will want to create button class which handles its state (MouseOver,Pressed,Unpressed), size and position.
Finally style or how you want your buttons to look. one possible method would be a 9-Patch, which is essentially 9 tiny images that are repeated in such a way to form a stretchable button.
9 Patch Resource - It's for android but the concept still applies
You can also take a look to see how other engines do it such as LibGDX.
Hope This Helps
I have a general question that is Java related.
I am writing an application that has a GUI menu. I am trying to change one part of the GUI menu based on the selection of a Radio button.
Do I need to:
Redraw the whole window or just update that part with:
setVisible(true)?
If I just use the statement from #1 above .. the GUI is fine -- until I move the mouse over it and then I see the previous button choice. What am I doing wrong?
Swing components have a repaint(), revalidate(), and doLayout() method. One of those should probably be able to redraw whichever pieces you want. However, doLayout is not something that you should be taking responsibility for, that's the layout engines responsibility.
You may also want to check out this post, the first response has a pretty good explanation, and links to an article with more detail.
In terms of the second part of your question, I'm not sure, but we may need to see some code to get an idea. Is the 'replaced area' actually being removed from the view?
..in my application the user select which device platform type they want top test (that choice is a set of two radio buttons on the left). When the user selects either Android or iOS, the center grouping of check boxes changes to reflect a group of android devices they can test or a group of iOS devices that they can test.
Put a panel in the 'center grouping'.
Use a CardLayout for the panel.
Add both iOS & Android controls to the panel with the card layout.
Flip between them as needed.
Call revalidate() on the top level component.
I don't know if it's a dumb question because it is one of my first apps.. but if that's the case, please also explain why!
If I create a Tab-Based Activity-Structure, I get nearly what I am asking for but only for Tabs. What I want is generally opening a second or even third activity in one main-activity which contains the main-interface.
Example: I have a Title-Bar and a little icon at the bottom-left corner for some reason during the whole app runtime. Now: How can I control them with the main activity and open at the same time some other activities/views into the existing interface? It should then be shown below the title bar and lying underneath the little icon (the icon is not really important, just fictional). Also it would be nice if I could add some fade in effects to these embedded activities/views. Is that somehow possible?
I currently only know, how to open activities each over another filling the whole screen, except in the case of tabs... maybe I only haven't inspected the tab structure enough.. however, I would be delighted about each answer!
Regards
What you are looking for, are Fragments.
Fragments can be used to fill a part of the screen, while doing something else entirely in a different one.
In your example you can create a main activity that contains two Fragments. One Fragment controls the title bar, the other one controls the main content area.
By replacing the current Fragment in your content area with a different one on the press of a button, you can achieve the behavior you are looking for. At least, that's how I did it in an app of mine containing a main content area and a music player. The music player stays in place while the main content changes.
Sadly I can't provide any example code right now, but here is a tutorialthat should help you get started:
Android User Interface Design: Working With Fragments
Android has many useful tools when coming to views and screens and layouts.
Description: While playing my game (running around as a zombie bear eating humans) I would like to allow the player to access an items menu via sliding a menu from the right side/edge of the screen. Or at the least be able to access a game options menu (not game settings which would be the menu button).
What would be the best fit for description?
P.S How would I make a question like this less like a discussion and more like a straight forward programming question when I don't really know what's available to do this.
Also, if this is the case, please point me to another location to ask a question that may require a discussion.
Thank You!
Try looking at the SlidingDrawer class.
PS I personally don't see a problem with how you have worded your question if you are looking for ideas of views/widgets you need to perform a specific function/effect.
My first thought, and for a simple approach (this wouldn't be animated or dragged really), would be using a RelativeLayout where the portion representing the menu was initially set so that it's visibility were GONE, except for a small tab or arrow or something. When that tab/arrow is touched, the visibility of the View for the menu could be toggled to VISIBLE.
With visibility set to GONE, a view is not drawn or considered in any part of the layout pass when the screen is drawn.
You could populate a listview with some icons and when an particular icon is selected, then figure out which one was selected and then execute some function and hide the sidebar using an animation. I've never developed a game, so I'm not too sure how far it deviates from the standard, but I wish you the best of luck :) ! If you post the source let me know would love to test your game and see how you work with the source!