The role of SetID () in Android ImageView

Source: Internet
Author: User

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

Contact Us

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.