Making floating bubbles - android

I'm trying to make the background of my app have randomly floating bubbles. I've been looking around for anything similar, such as falling snowflakes, rain, etc. but I can't seem to find any examples.
Even if I can't make a bubble.png float randomly upwards, I'd like to at least have a . character or something that could represent "bubbles" like in a soda.
Any ideas or references? Thanks!

You could place a SurfaceView behind your primary UI in a FrameLayout and draw the bubbles in the SurfaceView following one of the available tutorials. The rest of your UI would then overlay on top.
Example:
<FrameLayout android:layout_width="match_parent"
android:layout_height="match_parent">
<SurfaceView android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/surface" />
<FrameLayout android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/app_content">
<!-- Normal app UI goes here -->
</FrameLayout>
</FrameLayout>
Warning: No matter what approach you take you're going to be redrawing the entire screen quite frequently several times per frame. (Animating the background plus drawing the UI.) Some ways will be faster than others but you are choosing to do more work than most apps do in drawing their UI. You will need to be mindful of performance and small inefficiencies; they will add up quickly.

Related

(Android) ScrollView stutters on fling with long multiline EditTtext inside

I have the following problem, and I cannot figure out how to eve try solving it (or whether there is a way):
My problem
I have SrollView, containing to EditText input fields. One is a single line, below is a multiline. Everything's fine and works as expected, up until I put too much stuff into the multiline EditText. When I fast scroll the view, the scrolling skips and stutters, very obviously, the whole effect is rather disturbing. tried on a Galaxy S3 with a custom AOSP ROM, and Note 4 with official 5.1.1, no difference at all.
I would expect a very heavy EditText makes it difficult to smoothly redraw on a fling, but this starts happening with relatively short text (approx 4-5 screen-pages long).
Edit: This also seems to happen on a simple scroll, when I do as much as touch it and move it a few lines (scrolling is not near to being smooth, that is)
The setup
I have reduced the widgets to the bare minimum, even removed padding, only the problem does not improve. From the Java code I also removed anything (any styling, or typeface, anything that affects the widgets at all), still no improvement.
If this is of any significance, the ScrollView in question is inside a fragment, that is one of two pages of a ViewPager. There is nothing else on this fragment ATM.
Here's the XML (as you will see, it's as base as possible):
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:singleLine="true"/>
<EditText
android:layout_width="match_parent"
android:layout_height="match_parent"
android:isScrollContainer="false"
android:inputType="textMultiLine"/>
</LinearLayout>
</ScrollView>
What I tried
Any advice I found regards only ListViews, and some attributes like android:smoothScrollbar, which have no effect here (I tried them all).
For the record, I did try out of frustration all of the below ( I know most of these has not much to do with ScrollViews, but I'm becoming hopeless here):
android:hardwareAccelerated="true"
android:fastScrollEnabled="true"
android:scrollingCache="true"
android:smoothScrollbar="true"
and also tried setting from the Java code things like
.setSmoothScrollingEnabled(true);
.fling(3500);
still no luck.
Question recap
Is there any way to make a simple widget like this scroll smoothly at all?
Thanks for your time if you've read through and even more if you answer. :)

Hide myactivity.xml has more than 80 views, bad for performance

Is it possible to hide this in XML file:
myactivity.xml has more than 80 views, bad for performance ?
I have a complicated UI. So, I want to hide this warning. I mean no way to switch UI into ListView, etc.
I think the issue here is the layering. If it has to layer 80 views on top of one another, that is really bad. Otherwise, that is a LOT to manage
You can see just how bad your UI performance is by using the Android tools in Developer Options > Debug GPU overdraw (on) and Show Surface updates to On. That will show you the performance issues.
Now to fix them, custom view XML'scontaining your subviews are the way to go.
Code maintainability is really important here. Right now a single one line change can screw up everything whereas with custom loaded subviews you minimize this greatly and ask a bit less of the OS at the onset potentially.
You can hide/ignore it by adding tools:ignore="TooManyViews" to the view that is making that error. For example:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
...
</LinearLayout>
will be
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
tools:ignore="TooManyViews">
...
</LinearLayout>
Note that this just hides the Lint warning and doesn't do anything else.

How to make a view from pieces aligned to each other with different behavior android

Let's say I have an animal face in pieces. I have an exterior, right ear, left ear, nose, mouse, eyes.
Each of this part is independent component, so even when all of it gathered into one, animation of nose is different from ears and doesn't happen at the same time.
So my question is how can I gather items together, so in future it will be a unit, but with separated behavior? Also I don't know how to place it, that ear is animating along the face, not overlaying and not with a hole between them.
Any ideas? Thanks.
Edit
This is an example of image I have (Original cannot share).
So on this image as on example nose, eyes, hair, eyebrows are separated elements. For example if I press on hair it will start one type of animation, if I drag nose (right or left) it will animate and change volume in video player.
My best idea for now is making each component as separated view and then in layout try to gather it together somehow, but I'm not sure it is correct and good idea at all.
Exactly as you wrote, make separated view for each element with specific listener. Extending View should be sufficient solution - it gives you needed interfaces (e.g. OnDragListener or OnClickListener) and let you to keep clear your solution.
This seems to me like really pleasant task, which you can solve step by step, task by taks, component by component...
As to container for all animal's parts, it depends on requirements. If in all cases the eyes, ears, hairs etc. would be on the same or proportional location for every animal and you put the animal more then once, it would be worth to think about custom ViewGroup - probably RelativeLayout.
It is hard to give you more precise tips, because there will be a lot of minor and major requirements like I mentioned. For example, if size of eyes' images of two different animals aren't equal I would my components (rather than View) extend ImageView, which gives us scaling features.
Edit: I' not sure it will be possible to accomplish it in this way, but I would try to do it like that:
<RelativeLayout ...>
<!-- LAYER 1: Face - background -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="100"
android:gravity="center">
<custom.path.FaceBaseComponent
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="60"
android:src="#drawable/face_drawable"/>
</LinearLayout>
<!-- LAYER 1: Ears -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center">
<!-- Left ear -->
<custom.path.EarComponent
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="30"
android:src="#drawable/left_ear"/>
<!-- Filler -->
<View
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="40"/>
<!-- Right ear -->
<custom.path.EarComponent
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="30"
android:src="#drawable/right_ear"/>
</LinearLayout>
</RelativeLayout>
This help you to save proportions between each element. Keep trying to merge as many "layers" as you can (maybe you can put ears and eyes inside single LinearLayout?).

Android 2D Game Architecture

I am creating a 2d puzzle game on android and want to get the community's input on a design decision. The basic design is this. There is a SurfaceView one which the 2d graphics are drawn in a background thread. Then I also have a RelativeLayout that overlays the surface view. The layout .xml looks like this:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/root"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center" >
<SurfaceView
android:id="#+id/game_surface"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
<RelativeLayout
android:id="#+id/game_overlay"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</RelativeLayout>
All touch events will be received by the game_overlay and will be routed to the game thread as needed. I will use LayoutInflater to inflate a layouts and place them inside game_overlay, then clear the game_overlay when needed. My rational for doing things way is that you get the best of both worlds. You don't have draw your own custom buttons to the canvas (Like a reset level button), rather leverage all that powerful android layout functionality. However you are able to perform the game rendering in the background, and have that thread stay alive all the time.
So now onto my questions. If you have tried something like this before I would like to hear your experience. Can I expect to pay a performance penalty for layering views like this? And more importantly would that performance hit be detrimental to the app's frame rate? Is there any other problem with this approach that you can spot.
For better game performance you should keep buttons at minimum since its for smart devices , try to rely on touch inputs for game play.
For custom buttons i disagree ,Also having your own buttons is better for visulation. It makes fancy your game.
And for your question yes you should avoid unnecessary capsulation. But i don't think it will cause a giant performance problem.
This can be a nice tutorial for surface click me

how to display multiple plots(linecharts) in android using achartengine?

i am new to programming and hence android programming.
I'm making an android app in which i have to show eeg data graphically (I mean dynamically in which data is received constantly and the graph is updated constantly with new values added to the right and the graph of old values moving to left and eventually out of view). now I could show 1 plot at a time but it would be really nice if I could show all plots (total 14) on a single screen from top to bottom. Now 14 charts may not be viewable at once, so i could add the function of scrolling so that some charts are visible at a time and others can be seen by scolling up or down.
I am using AChartengine for plotting. Is there some way to display multiple plots on a single screen from top to bottom with scrolling? Thanks for giving ur time.
I guess that, even if you could use a ScrollView to put many charts on same Activity/screen, it would be too heavy and chaotic. Why don't you multiplex data using different dataset for each graph? In this way you could have only some chart to display and data comparaison would be more intuitive...
You can make reference to "average temperature" inside achartengine examples, to know how to put different series (datasets) inside same chart.
Anyway, if you really want to create a 'long' scrolling screen with 14 charts, simply use a ScrollView like this:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:id="#+id/ScrollViewChartContainer" android:layout_width="fill_parent" android:layout_height="fill_parent">
<LinearLayout android:id="#+id/trendchart" android:layout_width="fill_parent" android:layout_height="match_parent" android:background="#android:color/transparent" android:orientation="horizontal" />
<LinearLayout android:id="#+id/trendchart2" android:layout_width="fill_parent" android:layout_height="match_parent" android:background="#android:color/transparent" android:orientation="horizontal" />
...
</ScrollView>
I have not tested such a layout, but it should work.

Categories

Resources