title: android simulate Recycler view on custom view
body: <p>i'm trying to simulate <code>RecyclerView</code> items on my custom view. i like to create simple TimeLine view and <code>ListView</code> or <code>Recycler View</code> not good for this idea, for example:</p>
  
  <p><a href="https://i.stack.imgur.com/khOzE.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/khOzE.png" alt="enter image description here"></a></p>
  
  <p>basically How can i pick the layouts to root viewgroup? for create above custom layout</p>
  
  <p>My xml view:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;RelativeLayout
      xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:tools="http://schemas.android.com/tools"
      android:id="@+id/root_layout"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      tools:context="ir.pishguy.timelineview.MainActivity"&gt;
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>My java code:</p>
  
  <pre><code>public class MainActivity extends AppCompatActivity {
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          ViewGroup inclusionViewGroup = (ViewGroup)findViewById(R.id.root_layout);
  
          View child1 = LayoutInflater.from(this).inflate(
                  R.layout.child_layout1, null);
          View child2 = LayoutInflater.from(this).inflate(
                  R.layout.child_layout2, null);
          inclusionViewGroup.addView(child1);
          inclusionViewGroup.addView(child2);
      }
  }
  </code></pre>
  
  <p>child_layout 1 and 2 are same:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
                android:orientation="vertical"
                android:layout_width="match_parent"
                android:background="#909090"
                android:layout_height="30dp"&gt;
      &lt;TextView
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:text="ddddd"/&gt;
  
  &lt;/LinearLayout&gt; 
  </code></pre>
  
  <p>My Solution:</p>
  
  <pre><code>public class MainActivity extends AppCompatActivity {
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          int placeholderId = R.id.reservedNamedId; // placeholderId==1
          ViewGroup placeholder = (ViewGroup)findViewById(placeholderId);
          for (int i=0; i&lt;3; i++){
              View child1 = LayoutInflater.from(this).inflate(
                      R.layout.child_layout1, null);
              child1.setId(i);
  
              RelativeLayout.LayoutParams p = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
                      ViewGroup.LayoutParams.WRAP_CONTENT);
  
              p.addRule(RelativeLayout.BELOW, R.id.reservedNamedId);
  
              child1.setLayoutParams(p);
  
              placeholder.addView(child1);
  
          }
      }
  }
  </code></pre>
  
  <p>Thanks.</p>