Activity vs. View. vs. SurfaceView and interaction - android

I am trying to make a fairly simple Android game. I am making a custom view: I am not using any buttons, rather, I am painting pixels on screen that represent buttons. The idea is that I have 3 screens:
A Main screen
A Play screen
An Instructions screen
The main menu has two "locations" to click on: one that says Play (via painted pixels) and another that says Instructions.
I am confused as to how these should be implemented. Right now, I have a Main activity that sets the content view to the Main screen (extends View) but I am confused as to how to go from that Main screen (View) to the Play or Instructions screen. I have read up on View, Activities and SurfaceView but without any luck in understanding.
Does anyone have any examples (with proper programming practices) to make a view interactive and show another View (potentially Activity that creates a View?) Thanks!

What you need are some basic Android game development tutorials. To get started, this short tutorial is well-arranged and covers a Main-Screen, which leads to a Game-Screen. It will definitely help you out to get started. I personally also like video-tutorials, that's why I would recommend this series of tutorials which is suitable for beginners, too. Finally this page shows a lot of Android gaming tutorials. That are my personal favorits as it comes to gaming tutorials for beginners, but you will find a lot of stuff out there in the web. Have fun!

Related

Multiple activities for displaying many images?

I developed an app for the iPhone that I would like to make for Android. However, because I was self taught with Xcode, I approached the project incorrectly. My app in it's basics loads a certain picture from a List View when the user selects the certain button associated with the picture they want. I had no programming experience when I started, so I just linked by drag and dropping roughly 300 buttons to 300 different scenes which displayed 300 different pictures in Xcode. Yes, it was very time consuming... My question is how should I approach my project to do the same function in Android Studio, but minimizing the amount of activities. I have the idea that it would be more beneficial to use code to have one List View activity that incorporates many buttons, that when pressed, will display the particular picture. Any recommendations for tutorials or videos as a place to start as I learn my way around Android Studio? Or am is it hopeless and I will have to have another roughly 300 Activities in Android Studio.
You can use fragment for acheving your purpose.
A Fragment is a piece of an activity which enable more modular
activity design. It will not be wrong if we say, a fragment is a kind
of sub-activity
Fragment you can think of it like a sub activity, which sits with in
an activity and which contributes its own UI to the activity screen.
Fragments are always part of an activity. With out an activity, a
fragment will not exist. So your fragment life cycle will always be
affected by activity life cycle. An activity can contain more than one
fragment. Similarly a fragment can be re used in multiple activities
Below links will help you to know more about fragment and how it's implemented in an android application
https://stackoverflow.com/a/13757241/4247543
https://www.raywenderlich.com/117838/introduction-to-android-fragments-tutorial
https://www.tutorialspoint.com/android/android_fragments.htm
https://developer.android.com/guide/components/fragments.html

Android implementation of tutorial screen

I'm planning to implement tutorial screen for Android app.
My plan is that tutorial screen looks like:
There are several screens and you can swipe between than. Every view has custom design. There are dots which represents every screen, and show what page are you watching now. I need good-looking transition with adequate animations.
This screen will be full screen activity.
I have found several Image Galery, but I don't want to slide between images, I need to slide between views.
I do not need exactly code for this. I need instruction in which way this can be done, and what elements I need to use in order to achieve targeted design.
Thanks in advance.
You'll want to use ViewPager in conjunction with Fragments, the instructions are on Android developer's website.

How do I learn to design a UI like this?

I was recently using the app Secret and was observing the amazing user-interface that it has. If you are opening Secret's webpage, please scroll down a little to see the UI.
Being someone who is still a novice in Android and wants to learn, I would like to ask how that UI has been designed. I could ask a lot many questions in this one post but I will limit myself to just one for now.
Whenever you click on one of those tiles, it opens up and shows the comments for that particular tile. The other tiles below and above disappear. When you click on the tile again, it smoothly animates back to its position and the tiles above and below come into view. How is this achieved?
What have I tried so far? Nothing, because it is a "where do I begin?" question.
This is probably an instance of a custom activity transition (and a particularly well polished one).
In general, you can use the overridePendingTransition() to specify an animation that must be run when the current activity is changed (a classic example is sliding in a new Activity from a direction, while the previous Activity exits in the opposite direction). However, these transitions generally do not share UI elements.
Chet Haase has done a few DevBytes (in particular this one) to "simulate" an activity transition that shares an UI element (i.e. a view) between the caller and called activities. For example, if you have a Gallery, and you click on an image to show it full-screen, you would probably want the image to "grow" smoothly until it occupies this new position. The trick to achieve this is to actually disable the standard transitions entirely and include in the Intent used to start the activity the information about the current position and dimensions of the view that you want to "share":
Intent subActivity = new Intent(this, PictureDetailsActivity.class);
subActivity.putExtra(PACKAGE + ".left", screenLocation[0]);
subActivity.putExtra(PACKAGE + ".top", screenLocation[1]);
subActivity.putExtra(PACKAGE + ".width", v.getWidth());
subActivity.putExtra(PACKAGE + ".height", v.getHeight());
startActivity(subActivity);
overridePendingTransition(0, 0);
Therefore, the new activity can extract this data, and with this information and the knowledge of where on the screen the view should end up, can build and execute an animation that simulates the desired effect.
This technique can be difficult to implement if you want a complex animation, so in Android L this was baked into the platform itself: Activity Transitions can handle this automatically and provide a few built-in animations to act on the remaining (i.e. non shared) views. For example, the explode transition seems to be very much like the one you describe.
Regarding layouts:
You might find it helpful to use hierarchy viewer, which offers a function to capture the layers of the UI and store them in a Photoshop file. This gives you a good idea how the layout of a particular app you are was created and what kind of views were used.
Regarding animations:
Checkout videos by Chet Haase and Romain Guy who discuss graphics and animations in detail.
You can start with the Android training guides.
This one is an overview of designing with media and animation, but this one uses a ViewPager to achieve the effect you want.

android tutorials screen

I was really confused about this topic, so I had to ask. Being new on Android, I was thinking of creating an introductory sort of tutorial like page for the app I am working on, like the one's you see on various apps that is used for the first time in which they point out various features of the app, what functionality does this button perform when pressed, what does the menu item do, in a sort of a dynamic way.
What are these actually ?? Are they splash screens? Or are they something really different?
I just made a tutorial screen for my app. What I did in my case was to :
1) Create snapshots of all the activities and their functions.
2) Then I used photoshop to put different markers defining the different areas in the snapshot and what they do. (which look similar to the link posted in the above comments)
3) Then I used an Imageswitcher with a next button at its bottom. At the start of the app if the user wants to view the tutorial I just start an activity with the Imageswitcher.
4) I then cycle through all the snapshots with the help of the next button below the ImageSwitcher.
5) On the last image of the ImageSwitcher I just launch an Intent to open the main screen of the actual app.
Hope this helps!!!

Opening an activity within a View in Android

I've recently started developing Android Apps, and whilst the model is making more sense the more I look at it, I cannot do something (nor find any reference material on it) which to me seems quite simple.
I have an activity which has five buttons along the bottom, and a blank View taking up the rest of the screen. I want, upon clicking these buttons, for an activity to be opened in (and confined to) this view. I can get a new activity running without incident, but this opens in a new screen.
If anyone can show me an easy way to launch a (sub/child?) activity within a view which is defined in the parent activity's layout xml file - equally, it could be created in the parent activity - you'd really be doing me a favor!
I'd recommend taking a look at TabHost. The tabhost is an Activity itself, and the sub-views are all Actvities as well.
Here is a good tutorial that'll get you going very quickly. There is a more work to create (optional) icons for the tabs (also describe in the tutorial).
Hope this helps.
Edit* You mentioned buttons being at the bottom of the screen. Take a look at this SO Question
You can achieve that by using an ActivityGroup... here is a simple example which shows how to do it using a TabActivity:
http://web.archive.org/web/20100816175634/http://blog.henriklarsentoft.com/2010/07/android-tabactivity-nested-activities/
Of course, you will have to change the code since you are not using TabActivities. Just take a look at the getLocalActivityManager and getDecorView methods that is what you will be using.

Categories

Resources