Android Programming code creation Layout instance Analysis _android

Source: Internet
Author: User

This example describes the use of code creation layouts for Android programming. Share to everyone for your reference, specific as follows:

Describe the effect: the outermost layer is a relativelayout with a custom linearlayout, each linearlayout has two textview. That ' s it!!!

private void Initview () {//get XML relativelayout layout = (relativelayout) Findviewbyid (R.id.liner); for (int i = 0; i < 5; i++) {Relativelayout.layoutparams relativeparams = new Relativelayout.layoutparams (Vie
   WGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
   Each row has a linearlayout linearlayout llayout = new LinearLayout (mcontext);
   Llayout.setid (i + 10);
   Llayout.setorientation (linearlayout.horizontal); Linearlayout.layoutparams llayoutlayoutparams = new Linearlayout.layoutparams (ViewGroup.LayoutParams.MATCH_PARENT,
   ViewGroup.LayoutParams.WRAP_CONTENT);
   Llayout.setlayoutparams (Llayoutlayoutparams);
   TextView TV = new TextView (mcontext);
   Tv.setid (i);
   Tv.settext ("This is the first" + i + "text box");
   Tv.settextcolor (Color.Blue);
   TextView tv_num = new TextView (mcontext);
   Tv_num.setid (i + 20);
   Tv_num.settext (i + "Taiwan");
   Tv_num.settextcolor (color.red); Add a long height setting for textview linearlayout.layoutparams layoutparams_txt = NEW linearlayout.layoutparams (ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
   Tv.setlayoutparams (Layoutparams_txt);
   Tv_num.setlayoutparams (Layoutparams_txt);
   Add to the LinearLayout in each row llayout.addview (TV);
   Llayout.addview (Tv_num);
   Each linearlayout is under the previous one, the first at the top, not the IF (i > 0) {relativeparams.addrule (relativelayout.below, i + 10-1);
  //Add each linearlayout to the Relativelayout Layout.addview (Llayout, relativeparams);

 }
}

I hope this article will help you with your Android programming.

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.