Results 1 to 1 of 1
  1. #1
    Zarah is offline Senior Member
    Join Date
    Mar 2014
    Posts
    119
    Rep Power
    0

    Default Creating Layout Programmatically- Questions

    I have a couple of questions from the following code snippet:
    Java Code:
    @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            // creating LinearLayout
            LinearLayout linLayout = new LinearLayout(this); //****QUESTION 2*********
            // specifying vertical orientation
            linLayout.setOrientation(LinearLayout.VERTICAL);
            // creating LayoutParams  
            LayoutParams linLayoutParam = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); //*****QUESTION 1***
            // set LinearLayout as a root element of the screen 
            setContentView(linLayout, linLayoutParam);
        }
    1. The base class is ViewGroup.LayoutParams, that is LayoutParams is a nested class of ViewGroup. I had also read that it is a static nested class. So why don't we refer to it using the outer class' name and dot notation:

      Java Code:
      ViewGroup.LayoutParams linLayoutParam = new ViewGroup.LayoutParams(...);
    2. In the following statement, what object is "this"?

      Java Code:
      LinearLayout linLayout = new LinearLayout(this);
    Last edited by Zarah; 05-09-2014 at 08:04 PM.

Similar Threads

  1. Replies: 5
    Last Post: 10-16-2012, 02:10 PM
  2. How to programmatically press a key?
    By Sreejith S in forum New To Java
    Replies: 2
    Last Post: 04-21-2012, 05:54 AM
  3. Grid Layout change layout alignment of control s
    By rellicott in forum SWT / JFace
    Replies: 1
    Last Post: 02-13-2012, 06:11 PM
  4. Replies: 12
    Last Post: 02-05-2011, 12:24 PM
  5. Spring Layout questions.
    By rhonig in forum New To Java
    Replies: 0
    Last Post: 02-11-2010, 06:10 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •