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

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.

Related

Table Layout with dynamic amount of rows and dynamic content

Im pretty new to Android Development, so after like three days of trying different things with the XML Layout Design, i give up and hope for help from you guys.
What i want to achieve:
A table layout with with multiple rows, each filled with calculations im making in the background
The first three rows shall contain the input parameters, the following ~12 rows shall contain output parameters
rows 3 to 6 shall be rearrangeable, so to speak change name and shown values.
This is the concept, thats what one row should look like:
My way of trying things was:
Creating a TableRow for "Taupunkt" and "Td" and another one for three textfields and the +/- picture.
But how on earth am i supposed to insert the ">" arrows picture into the layout? Basically it should be centered between the rows.
I hope i did a clear explanation of my problem and hope that there is someone out there who can help me :)
PS.: App is going to support Android 4.0 and above
EDIT: As seen in the picture, how would i go about centering the plus/minus vertically to the textfields? Like, it should have the same space above and below it to the textfields
You can use ListView or RecyclerView as mentioned in comments.
For second question to make your view centrally aligned you can use android:gravity attribute in LinearLayout. Just made one same which is using center_vertical. Checkout -
<LinearLayout
android:id="#+id/btn_google"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="#dimen/standard_padding"
android:background="#drawable/rectangle_round_red"
android:gravity="center_vertical"
android:minHeight="#dimen/standard_height"
android:orientation="horizontal">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/icon_google" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Google"
android:textColor="#android:color/white"
android:textSize="#dimen/font_18" />
</LinearLayout>
This is how it looks

How to get spacing between two edit text boxes as the below attached image

The texts can be entered into them . Only these two text widgets are possible in the given activity. I would want to know the structure , I would have to employ to get result as such.
I am still in learning phase.
There's a lot of ways how to achieve that. I suggest you to start with reading this thoroughly to learn how to build layouts on Android.
In general, you can add spacing among views by adding some margin and/or padding.
If you want to replicate the particular design quickly, do this:
Have vertical LinearLayout as your root layout (with gray background).
Add two CardViews (one for each box). That will add the
background and spacing.
Add other views to those CardViews.
To give you something to work on
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"> //Elements inside this will be added vertically on the screen
<EditText
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_margin="10dp"
android:hint="First edittext"/>
<EditText
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="10dp"
android:hint="Second edittext"/>
</LinearLayout>
This is the basic structure on the image you showed. Expirement with it. Add your desired borders by using shapes and etc.

Android: How to add a vertical progress bar to a home screen widget?

I need to put a vertical scroll bar in a home screen widget, and after searching many times, I can't find a convenient solution that works on API3 and above!
I tried many solutions:
- using bitmap created at run-time, but on some displays it never reach 100%
- a patch9 bitmap, but the scroll bar display gets completely messed up when the progress is near 0.
- using the addView() with 100 existing layout and it works great, except it's only available since API7!
- including all 100 layouts and showing only one at a time, work fine, but what a mess to include those in my 8 different widget layouts!
I tried to use the weight programmatically but it's not possible either, any other solution to resize a view based on a %?
Here is one progress bar layout I currently use:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent" android:layout_height="fill_parent">
<ImageView android:layout_weight="11" android:layout_width="fill_parent"
android:layout_height="fill_parent" />
<ImageView android:src="#drawable/scale"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:layout_weight="89" />
</LinearLayout>
Only solution I found so far is to have all the possible progress levels ready to use in various Xml layout files.
On Android API < 7, all those need to be included in a single xml layout and shown/hidden at run-time, while on Android API >= 7, one can actually use addRemoteView() to include the desired layout in a much more efficient way!
You should use ScrollView! You must place this within a layout. By default, scrollview is for Vertical Scroll. If you want horizontal scroll you must specify HorizontalScrollView. Hope this helps

Making floating bubbles

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.

Drawing a board (checkers) for an Android App

I am an Android Newbie trying to use my VB experience (8yrs ago) and design a UI. I am trying to create a checkers board which in VB would be a form on which I add multiple resizable panel widgets contiguously as needed in multiple rows. Since these are panels I can either add a small image (coin) on it (with the panel as background) or even add another small panel with a color that I can make visible and invisible to represent the coins. I know describing a VB UI is bad but VB is meant to make form designs easy and it really does and that is the only language I can think in for UI.
I notice that android SDK does not nearly have enough widgets for me to use. The best I could think of is using a TableLayout with multiple rows. The thing I don't get is what do I use to represent a square? Is there something analogous to a VB panel widget? I don't want to use an image because I want the board to be auto adjust to the screen dimensions.
Could some one help me with some hints?
You could define the layout in XML using a horizontal LinearLayout and fill it with 8 ImageViews (or any other container that can show an image/color) and copy it 7 times in a vertical LinearLayout, similar to this:
<LinearLayout android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1" >
<ImageView android:id="#+id/square_1"
android:layout_weight="1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
<!-- Set image or background here --> />
<!-- Repeat the ImageView 7 times and change the id for every ImageView
you create -->
</LinearLayout>
<!-- Reapeat the LinearLayout 7 times too -->
</LinearLayout>
This will create 8 rows with 8 squares in each and all the squares will have the same size thanks to the weight property which indicates that they should all get equal space.
To use Java code to change image/background, you will have to use:
ImageView square_1 = (ImageView)findViewById(R.id.square_1);
square_1.setBackground(Color.yellow);
Read more in the Android SDK Reference here:
ImageView: http://developer.android.com/reference/android/widget/ImageView.html
LinearLayout: http://developer.android.com/reference/android/widget/LinearLayout.html
Hope this helps you along the way!

Categories

Resources