title: Align Items of RecyclerView in each row in android
body: <p>I'm using RecyclerView with StaggeredGridLayoutManager to show tables of courses in my application, and that was OK, like the picture below: </p>
  
  <p><a href="https://i.stack.imgur.com/8gYvM.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/8gYvM.jpg" alt="enter image description here"></a></p>
  
  <p>But, How can I adjust all Items of the second row to be started with the same line like the picture below: 
  <a href="https://i.stack.imgur.com/UKnAd.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/UKnAd.png" alt="enter image description here"></a></p>
  
  <p>This is my onCreateView() method in my fragment: </p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>   
  
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
  
          View rootView = inflater.inflate(R.layout.fragment_orders, container, false);
  
  
          recyclerView = (RecyclerView) rootView.findViewById(R.id.recycleView);
          adapter = new MyCustomAdapter(getActivity(), Data.getData());
          recyclerView.setAdapter(adapter);
          // First param is number of columns and second param is orientation i.e Vertical or Horizontal
          StaggeredGridLayoutManager gridLayoutManager = new StaggeredGridLayoutManager(3, StaggeredGridLayoutManager.VERTICAL);
          recyclerView.setLayoutManager(gridLayoutManager);
         
          return rootView;
      }
  }</code></pre>
  </div>
  </div>
  </p>
  
  <p>And this may Adapter MyCustomAdapter.java: </p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>public class MyCustomAdapter extends RecyclerView.Adapter&lt;MyCustomAdapter.MyViewHolder&gt; {
  
      private Context _context;
      private ArrayList&lt;Information&gt; data;
      private LayoutInflater inflater;
      private int previousPosition = 0;
    
      public MyCustomAdapter(Context context, ArrayList&lt;Information&gt; data) {
  
          this._context = context;
          this.data = data;
          inflater = LayoutInflater.from(context);
      }
  
      @Override
      public MyViewHolder onCreateViewHolder(ViewGroup parent, int position) {
  
          View view = inflater.inflate(R.layout.orders_row, parent, false);
  
          MyViewHolder holder = new MyViewHolder(view);
          return holder;
      }
  
      @Override
      public void onBindViewHolder(MyViewHolder myViewHolder, final int position) {
  
          if(position == 1){
              create_tablelayout(myViewHolder.itemView,position,3);
          }else if(position == 3){
              create_tablelayout(myViewHolder.itemView,position,8);
          }else if(position == 5){
              create_tablelayout(myViewHolder.itemView,position,1);
          }else
              create_tablelayout(myViewHolder.itemView,position,5);
  
          myViewHolder.num_tab.setText("Table # " + data.get(position).id);
          myViewHolder.server.setText(data.get(position).server);
        
  
          final Information infoData = data.get(position);
  
      }
  
      @Override
      public int getItemCount() {
          return data.size();
      }
  
      class MyViewHolder extends RecyclerView.ViewHolder{
  
          TextView num_tab;
          TextView server;
  
          public MyViewHolder(View itemView) {
              super(itemView);
  
              num_tab = (TextView) itemView.findViewById(R.id.num_table);
              server = (TextView) itemView.findViewById(R.id.server);
  
          }
      }
  
     
          /* Find Tablelayout defined in main.xml */
          TableLayout tablelayout = (TableLayout) convertView.findViewById(R.id.itemtablelayout);
          tablelayout.removeAllViews();
          for(int i = 0;i&lt;nbr_item; i++) {
              // Creating a new TextView
              TextView Order1 = new TextView(_context);
              Order1.setText("TESSST");
              Order1.setTextColor(Color.parseColor("#FF9900"));
              Order1.setTextSize(10);
              Order1.setLayoutParams(new TableRow.LayoutParams
                      (LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT));
              //===================
  
              //Prepare TableRow to be inserted
              TableRow row = new TableRow(_context);
              row.addView(Order1);
              row.setPadding(4,4,4,4);
              row.setGravity(Gravity.CENTER);
              row.setLayoutParams(new TableLayout.LayoutParams
                      (LinearLayout.LayoutParams.MATCH_PARENT,
                              LinearLayout.LayoutParams.WRAP_CONTENT));
  
  
              tablelayout.addView(row);
          }
      }
  }</code></pre>
  </div>
  </div>
  </p>
  
  <p>And This The fragment_orders.xml</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:app="http://schemas.android.com/apk/res-auto"
      android:orientation="vertical"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:background="@color/gray"&gt;
  
  &lt;LinearLayout
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:layout_margin="10dp"
      android:orientation="vertical"&gt;
  
      &lt;LinearLayout
          android:layout_marginTop="10dp"
          android:layout_width="match_parent"
          android:background="@color/white"
          android:layout_height="50dp"&gt;
      &lt;/LinearLayout&gt;
  
      &lt;android.support.v7.widget.RecyclerView
          android:id="@+id/recycleView"
          android:paddingLeft="@dimen/space"
          android:paddingRight="@dimen/space"
          android:layout_width="match_parent"
          android:layout_height="match_parent"&gt;
  
      &lt;/android.support.v7.widget.RecyclerView&gt;
  
  &lt;/LinearLayout&gt;
  
  &lt;/LinearLayout&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>Please help me, I have spent all my time with this issue, but I can't get anything similar</p>