title: Fix the relative layout at the bottom of the page programatically
body: <p>I have created a scrollView that contains all the layout of my activity. Inside the scrollview i create a linear layout with the vertical orientation, and inside it, with a for-loop, i create some relative layouts that contains images and textview. I need the scrollview because in some moments i can have many images inside the layout and the screen need to be scrolled.
  This is ok, all works correctly. My problem is after. As you can see at the bottom of the code, i create the last relative layout that contains a simple button. My problem is that this layout doesn't stay at the bottom of the page, but it move itself up and down in relations to the screen. So if there is only one image for example, the last relative layout goes at the top of the page, attached to the image. If there are many images it is at the bottom of the page.
  What i want to do is that the last relative layout stay always at the bottom of the page, also if there is only one image inside the screen.
  How can i modify my code for accomplish my objective? </p>
  
  <pre><code>            //SCROLL VIEW
              ScrollView scrollView = new ScrollView(this); //create a new scrollView
              scrollView.setBackground(getResources().getDrawable(R.drawable.background)); //give the background gradient
              scrollView.setLayoutParams(new ScrollView.LayoutParams(ScrollView.LayoutParams.MATCH_PARENT, //set the main params about the dynamic size of the scrollView
                                                           ScrollView.LayoutParams.MATCH_PARENT));
              scrollView.setPadding(0, 20, 0, 0);
  
              //LINEAR LAYOUT
              LinearLayout linearLayout = new LinearLayout(this); //create a new linearLayout
              linearLayout.setOrientation(LinearLayout.VERTICAL); //set the layout orientation
              linearLayout.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
                      LinearLayout.LayoutParams.WRAP_CONTENT));
  
              for (i=0; i&lt;= 3; i++) {
  
                  //RELATIVE LAYOUT
                  RelativeLayout relativeLayout = new RelativeLayout(this); //create a new relative layout
                  relativeLayout.setLayoutParams(new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.FILL_PARENT, //set main params about the width and height
                          RelativeLayout.LayoutParams.FILL_PARENT));
                  relativeLayout.setBackgroundColor(getResources().getColor(R.color.grayColor)); //set background color
                  LinearLayout.LayoutParams relativeParams = new LinearLayout.LayoutParams(
                          new LinearLayout.LayoutParams(
                                  LinearLayout.LayoutParams.MATCH_PARENT,
                                  LinearLayout.LayoutParams.WRAP_CONTENT));
                  relativeParams.setMargins(20, 20, 20, 0);
                  relativeLayout.setLayoutParams(relativeParams); //set declared params about layout to the relativeLayout
                  relativeLayout.requestLayout();
  
                  //IMAGE VIEW
                  ImageView selectedPhoto = new ImageView(this); //create a new imageView
                  //imageView code here
  
                  //TEXT VIEWS
                  TextView numberCopies = new TextView(this); //create new TextView
                  numberCopies.setLayoutParams(new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT));
                  numberCopies.setGravity(Gravity.CENTER); //set position to the center in confront to the parent
                                      RelativeLayout.LayoutParams layoutParamsNumberCopies = (RelativeLayout.LayoutParams) numberCopies.getLayoutParams();
                  layoutParamsNumberCopies.addRule(RelativeLayout.CENTER_HORIZONTAL); //add a rule to the layout params. We put his position at the horizontal center of the relative layout
                  numberCopies.setLayoutParams(layoutParamsNumberCopies); //set the layout rules to the textView
  
                  TextView priceCopies = new TextView(this);
                  priceCopies.setLayoutParams(new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT));
                  priceCopies.setGravity(Gravity.CENTER);
                  numberCopies.setPadding(25, 25, 25, 25);
                  priceCopies.setTextColor(getResources().getColor(R.color.redColor));
  
                 RelativeLayout.LayoutParams layoutParamsPriceCopies = (RelativeLayout.LayoutParams) priceCopies.getLayoutParams();
                  layoutParamsPriceCopies.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
                  layoutParamsPriceCopies.addRule(RelativeLayout.CENTER_VERTICAL);
                  priceCopies.setLayoutParams(layoutParamsPriceCopies);
  
                  relativeLayout.addView(selectedPhoto);
                  relativeLayout.addView(numberCopies);
                  relativeLayout.addView(priceCopies);
                  linearLayout.addView(relativeLayout);
              }
  
              //RELATIVE LAYOUT
              RelativeLayout relativeLayoutOpenButton = new RelativeLayout(this); //create a new relative layout for add the main buttons
              relativeLayoutOpenButton.setLayoutParams(new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, //add the params for the width and height
                      RelativeLayout.LayoutParams.WRAP_CONTENT));
              relativeLayoutOpenButton.setBackgroundColor(getResources().getColor(R.color.blackColor)); //set the black background
              relativeLayoutOpenButton.setPadding(10, 10, 10, 10); //set the padding
              LinearLayout.LayoutParams relativeParamsOpenButton = new LinearLayout.LayoutParams(
                      new LinearLayout.LayoutParams(
                              LinearLayout.LayoutParams.MATCH_PARENT,
                              LinearLayout.LayoutParams.WRAP_CONTENT));
              relativeParamsOpenButton.setMargins(0, 20, 0, 0); //put a top margin for separate the black bar from the last image line
              relativeParamsOpenButton.gravity = Gravity.BOTTOM; //set the gravity to the bottom
              relativeLayoutOpenButton.setLayoutParams(relativeParamsOpenButton);
              relativeLayoutOpenButton.requestLayout();
  
              Button confirmButton = new Button(this); //create a new button
              //code button here
              relativeLayoutOpenButton.addView(confirmButton); //add the button to the view
  
              scrollView.addView(linearLayout);
              setContentView(scrollView);
          }
  </code></pre>
  
  <p>Thanks</p>