<span id="Label3"></p><p><p>1,fragment: <span style="font-family: 宋体;">fragments</span> <span style="font-family: Calibri;">,</span> <span style="font-family: 宋体;">fragments</span></p></p><p><p>Application Scenario <span style="font-family: Calibri;">:</span><span style="font-family: 宋体;"></span><span style="font-family: Calibri;"></span> the <span style="font-family: 宋体;">navigation bar of Weibo</span></p></p><p><p>1.1 The <span style="font-family: 宋体;">controls introduced from the system after</span> <span style="font-family: 宋体;"></span> <span style="font-family: Calibri;">3.0</span> <span style="font-family: Calibri;">,</span> <span style="font-family: 宋体;">representing the part of the screen</span> <span style="font-family: Calibri;">,</span> <span style="font-family: 宋体;"> Because the previous draw control on the phone</span> is not a problem <span style="font-family: Calibri;">,</span> <span style="font-family: 宋体;">But if it is a flat interface</span> <span style="font-family: Calibri;">,</span> <span style="font-family: 宋体;">each time you draw a large number of controls on the resource consumption is very large</span> <span style="font-family: Calibri;">,</span> <span style="font-family: 宋体;">can cause stalling</span> .</p></p><p><p>Fragment <span style="font-family: 宋体;">allows the screen to update part of the interface first</span> <span style="font-family: Calibri;">,</span> which <span style="font-family: 宋体;">is part of the interface</span></p></p><p><p></p></p><p><p>Click on the sound to display the UI interface, click on the storage to display the storage interface, but not in the page jump, but the layout of the file, click Switch Layout file, through the modular to use</p></p><p><p>The Framelayout layout and fragment match best because it renders the fastest and most efficient</p></p><p><p>1.2,fragment Getting Started (create a main interface from the Tablet interface Above)</p></p><p><p>(0) define the main interface layout, individual fragment assign a piece of display space</p></p><p><p>① creates a class that inherits fragment (API11 can be used later), which is a lightweight activity that does not need to be defined in the manifest file</p></p><p><p>② creating a corresponding fragement layout file</p></p><p><p>③ overrides the Oncreateview () method, returning a View object</p></p><p><p>By Inflater (parameters passed in on the method). inflate (resource file, null), return to this view</p></p><p><p>(the Inflater.inflate (xxxx) method is called at the bottom of the View.inflate)</p></p><p><p>④ Creating an inherited class object in Mainactivity</p></p><p><p>Extendfragment EF =new extendfragment ();</p></p><p><p>Get Manager</p></p><p><p>Fragementmanager fm = Getfragementmanager ()</p></p><p><p>Get the fragment transaction through the manager, because one interface is either all updated successfully or all fails together</p></p><p><p>Fragmenttransaction ft = fm.getbegintransaction ();</p></p><p><p>Replace the method, one fragement replaces the other fragement</p></p><p><p>Ft.replace (assigned display Area Control id, inherited fragment);</p></p><p><p>and add the method of adding the fragement up</p></p><p><p>Ft.comit ();//submit</p></p><p><p>Extra: ① cannot initialize the control directly through the Findviewbyid (), but to find through the view returned by Inflater.inflate ();</p></p><p><p>Benefits of this approach: separation of business functions of the main interface and sub-interfaces, modularity, convenient post-maintenance, strong internal coupling</p></p><p><p>② If you have more than one fragement, consider taking the intermediate fetch manager to the commit and then passing in different fragement inheriting classes (all inherited fragement can define the parameters as Fragement)</p></p><p><p>③ transactions are useful only once, Comit () once, The next update interface must recreate the transaction</p></p><p><p></p></p><p><p>1.3 Fragment and Activity communication</p></p><p><p>The input value or other value of the Activity's main interface in the fragment inheriting class.</p></p><p><p>In fragment you can getactivity (). Findviewbyid (xxxid); get the corresponding control</p></p><p><p>Getactivity () Gets the activity it mounts</p></p><p><p>Need context can ditch through getactivity (); get context</p></p><p><p>Fragment can be transferred between the Activity.</p></p><p><p></p></p><p><p>The life cycle of the 1.4 fragment (a small activity) is almost identical to the life cycle of the Activity.</p></p><p><p>Oncreate (), ondestory (), onStart (), onStop (), onresume (), onPause ();</p></p><p><p>But it has no setcontentview (), some oncreateview () (important);</p></p><p><p>If it is replaced by replace, the equivalent is to go destroy three methods: onstop), onPause (), ondestory ()</p></p><p><p></p></p><p><p>1.5 Fragment backwards compatible (it has two packages app pack, 4.0 later, V4 package compatible API 4 Version)</p></p><p><p>Spoofing the Eclipse Compiler: if you modify the minimum version without modifying the code, the compiler does not check the Code.</p></p><p><p>Supportx.jar backwards compatible jar//low version of the phone want to use the higher version of Things will introduce Supportx.jar package</p></p><p><p></p></p><p><p>however, This compatible jar package is used in a different way</p></p><p><p>When using fragment in a Jar package with API 4</p></p><p><p>Getfragmentmanager () This method is not available. use fragementactivity when inheriting activity</p></p><p><p>Then pass Getsupportfragementmanager (). begintransaction (); get manager and transaction</p></p><p><p>And then it's the same as Above.</p></p><p><p>This backward-compatible notation is available in higher versions, as long as the corresponding Supportx.jar package is Imported.</p></p><p><p></p></p><p><p>2.View Animation</p></p><p><p>Define a button and place the ImageView control to do an animated presentation</p></p><p><p>Define a few buttons to do specific animations, transparency alpha, displacement trans, Zoom scale, rotate Animation rotate</p></p><p><p>2.1 Transparency Change Animation API Alphaanimation AA = new (start Transparency (0.0 fully transparent), end transparency (1.0 completely opaque))</p></p><p><p>Aa.setduration (2000);//the length of time the animation is played</p></p><p><p>Aa.setrepeatcount (2);//repeat play n+1 times, animation.infinite//cycle times</p></p><p><p>Aa.setrepeatmode (aa. RESTART (positive Order)/aa. REVERSE (reverse after each play);//re-play mode</p></p><p><p>Iv (corresponding control). startanimation (aa);//start Animation</p></p><p><p></p></p><p><p>2.2-bit shift-shifted animation Api:translateanimation ta = new (1,2,3,4,5,6,7,8);</p></p><p><p>① the starting position of the reference: the control itself, the phone screen can be used as a referential, ainmation.relative_to_parent (refer to the parent form of the X-axis) relative_to_self (relative to Itself) (can be seen as the beginning of the Position)</p></p><p><p>② is 0, the proportional value of the reference system</p></p><p><p>③ Moving position reference: animation.relative_to_parent</p></p><p><p>④ Moving distance 200//is not a pixel, it represents 200 times times the width of the parent form! (running to Fly)</p></p><p><p>⑤-⑧ corresponding Y-axis parameters</p></p><p><p>Other animations that are equivalent to setting transparency</p></p><p><p></p></p><p><p>2.3, scaled animation</p></p><p><p>Api:scaleanimation SD = new (1,2,3,4,5,6,7,8) for scaled animations;</p></p><p><p>1,x scale in horizontal direction</p></p><p><p>2,x scale in horizontal direction</p></p><p><p>Reduction and amplification of 3-4 y</p></p><p><p>5 center point for x-axis scaling</p></p><p><p>6 Scale for X-axis scaling</p></p><p><p>7-8 the center point and scale of the y-axis</p></p><p><p>Other 4 parameter settings similar to transparency</p></p><p><p></p></p><p><p>2.4 Rotate Rotateanimation ra = new (start angle, end Angle)//default to the upper left of the control as the origin point</p></p><p><p>There is also a construction method to set up a reference frame</p></p><p><p>Other parameters: play a single time length, repeat the number of times, play the mode,</p></p><p><p>Start playback</p></p><p><p></p></p><p><p>2.5. Combined animation playback</p></p><p><p>The animations described above can be placed in a collection</p></p><p><p>Api:animationset set = new for animation collection (boolean If true both use the insertion of this animated collection, if false, use its own insert, or Mode)</p></p><p><p>Set.addanimation (animation);//add the corresponding sub-animation in</p></p><p><p></p></p><p><p>3.xml file Definition Animations</p></p><p><p>Create an animation folder, anim, create the corresponding XML file (with the default root node alpha, rotate, etc.)</p></p><p><p>Alpha tag in Alpha.xml</p></p><p><p>Properties: fromalpha, Toalpha start to end transparency (does not need to have the unit float strong Turn)</p></p><p><p>Duration: playback time, Repeatcount:infinte repeated playback, repeatmode: playback mode</p></p><p><p>translate in translate tags in XML files</p></p><p><p>Fromxdelta= referential coordinate system (0)</p></p><p><p>Toxdelta = (0 hardly moved, 100% relative to its own 100%p relative to the parent Form)</p></p><p><p></p></p><p><p>Pivotx in the scale label, pivoty specifies the coordinates of the center point (both set 50% for its own center)</p></p><p><p></p></p><p><p>Animation AA = animationutils.loadanimation (this,r.anim. corresponding File)</p></p><p><p>Iv.startanimation (aa)</p></p><p><p>Use this resource file in your code: get through the tool class</p></p><p><p></p></p><p><p>Set Animation collection XML file Settings: can not be directly introduced, to the other several XML files to copy the Contents.</p></p><p><p>The animation will revert back to the original style, with a fillafter = True in the tag properties of these XML files, and not the change will be the Same.</p></p><p><p>Animation construction Method parameters, time, Cycle times, playback mode is the same as in the corresponding XML file Set.</p></p><p><p></p></p><p><p>4 View animation Details questions:</p></p><p><p>Open developer options to display touch actions</p></p><p><p>When using the displacement animation, the set Click event is only valid when clicked on the original position, and clicking on the moving animation is not valid. The view animation essentially has no change, and the movement seen is just the system drawing, through the matrix changes, not imageview the actual Position.</p></p><p><p>5, attribute Animation (only introduced after 3.0,api11)</p></p><p><p>5.1</p></p><p><p>Differences in properties, fields, member variables</p></p><p><p>If you declare a private variable directly without providing a public access, it is just a member variable</p></p><p><p>If public access is provided, the member variable can be interpreted as a property (as long as the view Animation's member variable has the Setget method, it can be played with property Animations)</p></p><p><p>Animate the ImageView to set the</p></p><p><p>Iv.settranslationx ()</p></p><p><p>Iv.gettranslationx ()///these Two Setget methods can change the member variable of a translation into a property</p></p><p><p>Objectanimatior OA = Objectanimatior.offloat (modified Object (view object), property name (translationx), variable Parameter)</p></p><p><p>Translationx Pan position: Pixel point</p></p><p><p>Variable parameter float array, where you can either new an array or pass in multiple float numbers</p></p><p><p>Oa.setduration (2000);//the length of time the animation is played</p></p><p><p>Oa.setrepartcount (objectanimator.infinite)//here with Objectanimatior</p></p><p><p>Oa.setrepartmode (objectanimator.restart (2))</p></p><p><p>Oa.start ()//start The animation, the moving process will be moved by the float array</p></p><p><p>The motion of a property animation can be clicked, it not only has animation effect, but also moves the ImageView Control.</p></p><p><p></p></p><p><p>5.2 Extra (you can animate a property with a Setget method as long as the member variable such as Alpha,scale,translation,rotate (Rotation) in the ImageView control is Available)</p></p><p><p>Setxxtype can set a reference frame</p></p><p><p>Note: The property is imageview, not the attribute in alphaanimation, and the property name starts with lowercase</p></p><p><p>Rotatex properties, Rotated by x-axis, rotatey, centered on y-axis (can be seen as 3D Effect)</p></p><p><p>Alpha Transparency change, objectanimatior.offloat (modified View object, name of property, variable parameter (change of Transparency))</p></p><p><p></p></p><p><p>Collection of Animations: If it is an attribute animation, playing a set is simple, defining two individual property animations, and then calling the start () method at the same time to play Together.</p></p><p><p>I want to move by diagonal, define two displacement property animations, one control x axis, one control y axis</p></p><p><p></p></p><p><p>Animatiorset set = new Ainmatiorset ()//define The collection of animations</p></p><p><p>set.playsequentially (variable parameters of Animatior)//play sequentially, Playtogether ()//play together</p></p><p><p>Set.start ()//start Playback</p></p><p><p></p></p><p><p>5.3 XML definition Property animations</p></p><p><p>Create a folder animator Properties animation folder</p></p><p><p>Create a animator property animation for the root node</p></p><p><p>There is a PropertyName property in animator that can specify the corresponding property name, but there is no mutable parameter, such as the property of Alpha transparency, which directly specifies the transparency at which the valuefrom starts and the Valueto ENDS.</p></p><p><p>How to use in Code: convert an animated resource into an animated object</p></p><p><p>Animator Animator = animatorinflater.loadanimator (this,r.animator. file id);</p></p><p><p>Animator.settarget (iv)//specify the controls to play</p></p><p><p>Animator.start (); Start playback</p></p><p><p>If you want a collection of property animations, create a child node as set XML file, put the animator nodes that need to be played together (in order, a animator node corresponding to an animation Effect)</p></p><p><p>Using property animations is also recommended in code, because the variable parameter float array changes the more spiritual, the resource file can only write the initial and the end, compared with less fine</p></p><p><p></p></p><p><p>6 Anti-compilation of the application</p></p><p><p>APK is in the bin directory of the corresponding project. the apk file is essentially a zip file</p></p><p><p>The list and layout files are garbled after the decompression, because they are encrypted when the APK file is Generated.</p></p><p><p>Tool Android Anti-compilation assistant: need to configure Java environment variables, require JDK7 above (my computer has a problem, not fixed temporarily)</p></p><p><p></p></p><p><p>Android13_fragment_view Animation _ Property Animation</p></p></span>
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service