title: Scroll horizontally in programmatically created ScrollView
body: <p>I'm creating a ScrollView, nesting in a RelativeLayout (which contains tables). Everything is properly added to the layout. The problem is: vertically scrolling works fine, but horizontal scrolling does NOT work at all. I already tested various combinations of <code>MATCH_PARENT</code>, <code>WRAP_CONTENT</code> and <code>FILL_PARENT</code>. No try even worked close. So my question is: What am I missing here?</p>
  
  <blockquote>
    <p>Here is the code:</p>
  </blockquote>
  
  <pre><code>public class PlayerView extends View {
  
      private RelativeLayout relativeLayout;
      private TableLayout tableLayout;
      private int player_loop;
      private int player_count;
  
      public PlayerView(Context context, int player_count){
          super(context);
          setPlayer_count(player_count);
      }
  
      public ScrollView create_scrollView(){
  
          ScrollView scrollView = new ScrollView(getContext());
          ScrollView.LayoutParams scroll_params = new ScrollView.LayoutParams(
                  ScrollView.LayoutParams.MATCH_PARENT,
                  ScrollView.LayoutParams.MATCH_PARENT
          );
          scrollView.setLayoutParams(scroll_params);
          scrollView.addView(create_relativeLayout());
  
          return scrollView;
      }
  
      public RelativeLayout create_relativeLayout(){
  
          relativeLayout = new RelativeLayout(getContext());
          RelativeLayout.LayoutParams relativeParams = new RelativeLayout.LayoutParams(
                  RelativeLayout.LayoutParams.MATCH_PARENT,
                  RelativeLayout.LayoutParams.MATCH_PARENT
          );
          relativeLayout.setLayoutParams(relativeParams);
          create_Player_Table_Layout();
  
          return relativeLayout;
      }
  
      public void create_Player_Table_Layout(){
  
          for(player_loop = 1; player_loop &lt;= player_count; player_loop++){
  
              relativeLayout.addView(player_table(getResources().getString(R.string.dummy_player_name) + player_loop, player_loop));
  
          }
      }
  
      public TableLayout player_table(String playername, int playernumber){
  
          tableLayout = new TableLayout(getContext());
          tableLayout.setId(playernumber * 1000);
  
          if (playernumber &gt; 1) {
  
              //TABLE PLACEMENT
              RelativeLayout.LayoutParams tbl_params_New = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
              tbl_params_New.addRule(RelativeLayout.RIGHT_OF, (playernumber - 1) * 1000);
              tableLayout.setLayoutParams(tbl_params_New);
          }
  
          //Add Playername
          TableRow row_playername = new TableRow(getContext());
          TextView view_name = new TextView(getContext());
  
          TableRow.LayoutParams view_name_params = new TableRow.LayoutParams();
          view_name_params.setMargins(20,20,20,20);
  
          view_name.setLayoutParams(view_name_params);
          view_name.setGravity(Gravity.CENTER);
          view_name.setText(playername);
          view_name.setTextSize(20);
          view_name.setId(playernumber * 100);
  
          row_playername.addView(view_name);
          tableLayout.addView(row_playername);
  
          //Add Lifepoints
          TableRow row_lifepoints = new TableRow(getContext());
          TextView view_lifepoints = new TextView(getContext());
  
          TableRow.LayoutParams view_lifepoints_params = new TableRow.LayoutParams();
          view_lifepoints_params.setMargins(20, 0, 20, 20);
  
          view_lifepoints.setText("40");
          view_lifepoints.setTextSize(40);
          view_lifepoints.setGravity(Gravity.CENTER);
          view_lifepoints.setId(playernumber * 100 + 10);
          view_lifepoints.setLayoutParams(view_lifepoints_params);
          row_lifepoints.addView(view_lifepoints);
          tableLayout.addView(row_lifepoints);
  
          Log.d("Test", "Player count:" + player_count);
          for(int opponent_loop = 1; opponent_loop &lt;= player_count; opponent_loop++){
              tableLayout.addView(commander_damage_from_player(player_loop, opponent_loop));
          }
  
          return tableLayout;
      }
  
      private TableRow commander_damage_from_player(int player_loop, int opponent_loop){
  
          TableRow row = new TableRow(getContext());
  
          TextView textView = new TextView(getContext());
  
          TableRow.LayoutParams layoutParams = new TableRow.LayoutParams();
          layoutParams.setMargins(20, 0, 40, 20);
          textView.setLayoutParams(layoutParams);
  
          textView.setText("0 | " + getResources().getString(R.string.dummy_player_name)+ " " + opponent_loop);
          textView.setTextSize(20);
          textView.setId(player_loop + 100 + opponent_loop);
          row.addView(textView);
  
          return row;
      }
  
      private void setPlayer_count(int player_count){
          this.player_count = player_count;
      }
  
  }
  </code></pre>
  
  <blockquote>
    <p>And for documentation the calling class:</p>
  </blockquote>
  
  <pre><code>public class Home extends AppCompatActivity {
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
  
          PlayerView playerView = new PlayerView(this, 8);
          setContentView(playerView.create_scrollView());
  
      }
  }
  </code></pre>