As Borg developers are constantly looking for perfection in their snippets. In many mature development environment emerge patterns and methods that give developers an spagettifri workday. A good example of maturity we see in JavaScript and frontend general, the field in recent years have been characterized by a maturation process in which the methods and patterns have gained almost osram cool blue complete domination.
Last academic meeting I held a two-hour introduction to how difficult and free way Android can be, at least in light of the fact that an app that will work on all mobiles and tablets from Android 2.2 through to 4.1, with UI patterns osram cool blue (ActionBar, Holo theme and fragments) from 3.0 that bakoverporteres and de facto UI patters that Sliding Menu etc.
Let's start with the fragments. What are they and what are they used for? To understand why fragments were implemented must understand how Google wants Android osram cool blue to be. Android was - until February 2011 - intended osram cool blue for use on devices with relatively small screens, typically mobile phones or music players and such. An Android app passed as an Activity and a View with a corresponding layout. Views in Android is turned so that they can "pumped up" osram cool blue with the data (inflate). Much magic stuff that makes lists and the like. With the introduction of larger devices, tablets, would a View inflates and simply look bad. One can not expect the same user experience on a phone on a tablet either, so something had to be done.
The solution was fragments. Now we no longer need to use Views, at least not on the Java side of the code, but it is still desirable Layouts. osram cool blue (Layouts are XML description of a View). The really big difference between the old and the new Views fragments, the fragments that are highly dynamic and can put just as many fragments on the screen as a mere wish. It is a relatively easy way to get a single app to turn around for the type of device it is on.
I / layout / directory has traditionally enjoyed XML descriptions of listviews, Layouts, Fragments osram cool blue and the like. This is still the place to do this, but with some clever tricks we can tell the app what our XML'er it is to be based.
/ Layout / - default osram cool blue folder, osram cool blue everything here will be used if there is a directory that fits better / layout sw600dp / - here we can XMLer distinct from / layout osram cool blue /. sw600dp corresponds 7 "or greater. / Layout sw720dp / - equals 10 "or larger (not used actively osram cool blue in our project)
From the picture we see two types of Device showing the same two fragments - but on tablets we run only a single Activity with two fragments, while on the phone, we have two different Activity'er osram cool blue with one fragment in each. To distinguish this we have the following files in the / layout / and / layout-sw600dp /: /layout/layout_main.xml <Front Layout android: id = "@ + id / main_fragment" android: layout_weight = "1" android: layout_width = "0DP" android: layout_height = "match_parent" /> /layout-sw600dp/layout_main.xml <Front Layout android: id = "@ + id / main_fragment" osram cool blue android: layout_weight osram cool blue = "1" android: layout_width = "0DP" osram cool blue android: layout_height = "match_parent" /> <Until Layout android: id = "@ + id / second_pane" android: layout_weight = "2" android: layout_width = "0DP" android: layout_height = "match_parent" />
Activity'en our know nothing about the type of device we are, so we have to check this. // Check if there is a right pane front layout front layout = (Layout Up) findViewById (R.id.second_pane); mDualPane = forward layout! = null && frameLayout.getVisibility () == View.VISIBLE;
mDualPane is true if Activity'en found id second_pane - and false if not. In other words, if fragment_main.xml from / layout / directory was eaten, it will not find any second_pane. It will however do if eating fragment_main.xml from / layout sp600dp / directory.
insertRightFragment () allows an operation where Fram Layout with id main_fragment are replaced with the appropriate fragment, while insertLeftFragment () replacing Front Layout with id second_pane. Since we only have second_pane the tablet edition of the layout of ours, so we must be careful that we only replace it if it exists:-)
Furthermore, the project used four library that does the following: ActionBarSherlock - Action Bars stock all the way back to Android 2.1 ViewPagerIndicator - provides an indication of the type of a ViewPager so it looks like tab'er as a potentially can swipe through HoloEverywhere - ensures that Holo- theme that came in Honeycomb comes with the earlier version of Android SlidingMenu - a menu that can slides in from the side
Great work! To begin an Android project from scratch every time is the cumbersome, and you've happily their own "bootstraps" a driver to process the by each project. But here one can help the better t
No comments:
Post a Comment