What does it do when you generate ImageView by code and add it to the layout, and you may encounter the SetID () method?
functions as follows:
When you add controls such as ImageView, TextView, and so on by code, you sometimes use the Addrule () method for layouts such as relativelayout.layoutparams, such as the following code:
ImageView ImageView = new ImageView (this.getactivity ()); Imageview.setid (View.generateviewid ()); Params.addrule ( Relativelayout.below, Imageview.getid ());
At this point we can know the role of SetID (). It is in the bottom of a control, above and so on to the specific view of the place, need GetID ().
Attach a complete code, but no SetID (), ImageView no ID, direct fetch will cause errors.
Relativelayout layout = new Relativelayout (this.getactivity ()); Layout.setlayoutparams (New Relativelayout.layoutparams (Layoutparams.fill_parent, Layoutparams.fil L_parent)); Layout.setbackgroundcolor (Color.parsecolor ("#CCCDCDCD")); ImageView ImageView = new ImageView (this.getactivity ()); Relativelayout.layoutparams params = new Relativelayout.layoutparams (RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT); Params.addrule (relativelayout.center_in_parent); Imageview.setlayoutparams (params); Imageview.setbackgroundresource (r.drawable.create_template); Animationdrawable frameanimation = (animationdrawable) imageview.getbackground (); if (frameanimation! = null) {Frameanimation.start (); } TextView TextView = new TextView (this.getactivity ()); params = new Relativelayout.layoutparams (RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT); Params.addrule (RelativelAyout. BELOW, Imageview.getid ()); Textview.setlayoutparams (params); Textview.settext ("Generating information ..."); Layout.addview (ImageView); Layout.addview (TextView); return layout;
The role of SetID () in Android ImageView