what element to be used to display dynamic moving screens in android - android

what element to be used to display dynamic moving screens in android, what I want to do in my app is to show 3-4 screens to the user moving dynamically based on a predefined time interval of 2-3 seconds.
I am new-bie to android, so wanted to understand how this can be programmed.
Many Thanks !

use viewpager
Layout manager that allows the user to flip left and right through pages of data. You supply an implementation of a PagerAdapter to generate the pages that the view shows.
http://developer.android.com/reference/android/support/v4/view/ViewPager.html

Related

Why did performance of my Android phone app suddenly degrade?

I wrote an Android app with an Activity that creates a heavily-populated scrollable screen image. While it used to take several seconds to display the result, as of two weeks ago, it now takes two minutes. And it is not responsive to scrolling motions. Does anyone have ideas on why the performance of my app would change so abruptly about two weeks ago?
Some detail...
Several years ago I wrote an app that collects simple golf statistics. The result after this year is a file with 149 records.
I also wrote an app to display those statistics. For one set of stats, I have an Activity that creates a low-tech stacked bar chart as follows.
My layout xml has a horizonally scrollable LinearLayout within which I have another empty horizontal LinearLayout.
In my program I add vertical LinearLayouts to the empty horizontal layout. Each
vertical layout represent a stacked bar; there are 3 stacked bars for each record in the file or approximately 450 of them.
Then, to each of the vertical layouts I add small TextViews representing elements of the stacked bar. Two thirds of the vertical layouts have 36 TextViews, and one third have as many as 80 TextViews.
Then I color the TextViews to represent parts of the stacked bar.
So I build one scrollable view with almost 23000 TextViews.
I've used this app for several years. It took several seconds to display the resulting bar graph. Once the result was displayed it scrolled smoothly. That performance is acceptable to me, as my app doesn't need to be doing anything else during this processing.
Beginning about two weeks ago, it now takes some two minutes to display the result, and it only intermittently responds to a scrolling motion. This began when I started making changes in another Activity in the app. I haven't touched the Activity that creates the stacked bar chart, but, of course the whole app gets recompiled.
So I added some logging statements to the Activity, and, based on logcat, it now takes about 1 minute to create the LinearLayouts and TextViews and color all the TextViews. But the screen, remained black for another minute before the chart appears. During this time (ie. after the creation/coloring of bars) and also when I try to scroll the display, the logcat contains occasional messages of the form "Skipped xxxx frames! The application may be doing too much work on its main thread." This doesn't seem related to my code, as it has completed it's work by this time.
I've read about vsync. Is my problem related to that? If so, is vsync relatively new? If that's now the problem, is there a way to circumvent it?
As extra credit, I'm open to suggestions for more efficiently creating a stacked bar graph!
1 use recyclerview
Android recyclerview is the most advanced version of the listview. basically, an android listview is used to present a simple data set. if you want to display large data set in your app, you should use recyclerview.
2 Use constrain layout and avoid nested layout
It is a common misconception that using the basic layout structures leads to the most efficient layouts. However, each widget and layout you add to your application requires initialization, layout, and drawing. For example, using nested instances of LinearLayout can lead to an excessively deep view hierarchy.

Periodically change views

I'm trying to create an activity that consists of multiple layouts (imagine newspaper sections like 'News', 'World News', 'Sport'...and so on) that periodically change their content. So every x seconds a different news story is shown.
What's the most efficient way to do this in android?
I started out with my own layout. And just updated the different TextViews and ImageView programatically. That worked fine, except for image loading, as for the lack of view recycling the image was reloaded every time a certain story was displayed. This caused a noticeable lag (even when using Picassos image caching) as all the layouts were updating their news story at the same time.
Than I looked at ViewFlipper. Now I inflate multiple layouts programatically (one for each news story) and add it to the ViewFlipper (one for each news section). Once that is done everything runs pretty smoothly. But it takes ages until all those layouts are inflated.
So what's the best way to go here? I couldn't find any good examples online but maybe I'm just missing the right term to google for.
Thanks for any help.
Consider using a looping ViewPager. A ViewPager typically will preload the side of the pages when the current page is displayed, so that reduce the lag. There's a library for that. https://github.com/imbryk/LoopingViewPager. Hope this helps.

Which layout/view/class to use to implement a slider?

Here is what I wish to implement..
A slider like thing...
Say My app is a game with 4x4 array of level buttons in each screen
and there are totally 3 screens...
The user should be able to swipe his finger from right to left and the
slider should "slide" to next 4x4 set of levels...
Just like what the phone functions while we open apps from homescreen. And if the user swipes his finger from right to left and there are no levels to the left, the slider should bounce back...
So... What I ask is which layout/view/class to use to implement such a slider?
Also, plz inform me how can I implement such a slider which switches between tabs as well (each tab containing different layouts).. I hope I made myself clear...
As i understand you can use:
gallery and for each row create your own viw
ViewPager - like in android market (slide between view)
All of this approaches uses adapters and listeners - you can find a lot of examples in internet. I think in your case viewPager is mor useful, because as i understand you want to have many different views.

Toggle part of a ViewFlipper view in android

I am using a ViewFlipper to toggle between views. I would like to get the same effect as Facebook's or Youtube's settings views, which is to keep a bit of the last view showing to the right. See image below. How can I do this?
Instead of using a ViewFlipper, try a ViewPager. The ViewPager is best, I think, if you want to have different pages and let the user control which one they see. It uses the paging animation by default, and you can specify page width so the user can see parts of the page next to it.

What is the best way to slide/switch between views ? (Custom Launcher)

I Build a Custom Launcher.
The launcher is made of views (each view will contain applications, images etc..)
The user can switch between those views in the home screen (almost like in every other laucncher)
the big difference is that in the launcher i build, when the user is in a specific view, he should be able to see the edges of the prev and/or the next view (if those are exist)
I tried to implement it by having a Horizontal Linear layout that holds the views.
It performs pretty nice, but not smooth enough.
I Concidered using viewflipper, but the problem with it, is that i can't see the prev and the next view.. (am i right?)
How should i implement this system?
thanks
Try to use ViewPager (android.support.v4.view.ViewPager). You need to download this .jar file to use it. http://developer.android.com/sdk/compatibility-library.html
Gallery already does this. It has issues with the smoothness and predictability of the left/right scrolling, but it will easily show your central view and the edges of the two neighboring views.

Categories

Resources