title: android dynamically created spinner not scrolling
body: <p>I have created a layout dynamically and added spinner and swipe layout to it via code in a fragment instead of xml files.</p>
  
  <p>Everything works fine except that the spinner does not scroll.</p>
  
  <p>The spinner's onItemSelected methods works fine though.</p>
  
  <p>Here is the code inside onCreate method of the Fragment.</p>
  
  <p>The canScrollVertically(-1) and canScrollVertically(1) methods for spinner return false. There is a main relative layout which contains two items. A spinner and then a swipe layout that is positioned below it. Swipe layout contains gridview.</p>
  
  <pre><code>parentLayout=new RelativeLayout(getContext());
              ViewGroup.LayoutParams lp=new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
              parentLayout.setLayoutParams(lp);
  
  swipeView = new SwipeRefreshLayout(getContext());
              swipeView.setRefreshing(true);
  
  swipeView.addView(gallery);
  
              mediaFolderSpinner = new Spinner(getContext());
              mediaFolderSpinner.setId(MEDIA_FOLDER_SPINNER_ID);
  
              spinnerArray = new ArrayList&lt;String&gt;();
              spinnerArray.add("All media");
              selectedFolder = spinnerArray.get(0);
              populateMediaFolders();
              spinnerArrayAdapter = new ArrayAdapter&lt;String&gt;(getContext(), android.R.layout.simple_spinner_dropdown_item, spinnerArray)
              {
                  @NonNull
                  @Override
                  public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
                      /*return super.getView(position, convertView, parent);*/
                      TextView lbl = (TextView) super.getView(position, convertView, parent);
                      lbl.setText(getItem(position));
                      lbl.setWidth(500);
                      lbl.setHeight(75);
                      lbl.setGravity(Gravity.START);
                      int paddingSidePixels = FileUtil.getPixelsFromDp(5);
                      lbl.setPadding(paddingSidePixels, lbl.getPaddingTop(), lbl.getPaddingRight(), lbl.getPaddingBottom());
                      lbl.setBackgroundColor(ContextCompat.getColor(getContext(), R.color.black));
                      lbl.setTextColor(ContextCompat.getColor(getContext(), R.color.white));
                      return lbl;
                  }
  
                  @Override
                  public View getDropDownView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
                      /*return super.getDropDownView(position, convertView, parent);*/
                      TextView lbl = (TextView) super.getView(position, convertView, parent);
                      lbl.setText(getItem(position));
                      lbl.setWidth(500);
                      lbl.setHeight(75);
                      lbl.setGravity(Gravity.START);
                      int paddingSidePixels = FileUtil.getPixelsFromDp(5);
                      lbl.setPadding(paddingSidePixels, lbl.getPaddingTop(), lbl.getPaddingRight(), lbl.getPaddingBottom());
                      lbl.setBackgroundColor(ContextCompat.getColor(getContext(), R.color.black));
                      lbl.setTextColor(ContextCompat.getColor(getContext(), R.color.white));
                      return lbl;
                  }
              };
              mediaFolderSpinner.setAdapter(spinnerArrayAdapter);
              mediaFolderSpinner.setBackgroundColor(ContextCompat.getColor(getContext(), R.color.black));
  
  
  
              mediaFolderSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
                  @Override
                  public void onItemSelected(AdapterView&lt;?&gt; parent, View view, int position, long id) {
                      selectedFolder = spinnerArrayAdapter.getItem(position);
                      galleryAdaptor.createGrid();
                  }
  
                  @Override
                  public void onNothingSelected(AdapterView&lt;?&gt; parent) {
  
                  }
              });
  
  
  
              parentLayout.addView(mediaFolderSpinner);
  
              RelativeLayout.LayoutParams rlp = (RelativeLayout.LayoutParams) mediaFolderSpinner.getLayoutParams();
              int marginPixels = FileUtil.getPixelsFromDp(5);
              rlp.setMargins(rlp.leftMargin, marginPixels, rlp.rightMargin, marginPixels);
              mediaFolderSpinner.setLayoutParams(rlp);
  
  
  
              parentLayout.addView(swipeView);
  
              if(TYPE == TYPE_IMAGE_VIDEO_MAIN) {
                  mediaFolderSpinner.setVisibility(View.VISIBLE);
  
                  RelativeLayout.LayoutParams swipeLp = (RelativeLayout.LayoutParams) swipeView.getLayoutParams();
                  swipeLp.addRule(RelativeLayout.BELOW, MEDIA_FOLDER_SPINNER_ID);
                  swipeView.setLayoutParams(swipeLp);
              }
              else{
                  mediaFolderSpinner.setVisibility(View.GONE);
              }
  </code></pre>