I tried adding views to RelativeLayout
holder with assigning left margin to layout params.
The views got added but margin was not given while adding, resulting in overlapping views .
My Java method to dynamically add Card (child view):
public void addCard(LinearLayout card)
{
LayoutParams params = new LayoutParams(card.getLayoutParams());
params.leftMargin = (this.mainHolder.getChildCount() * ((int) pxToDp(this.mContext.getResources().getDimension(R.dimen.card_margin)))) + 10;
this.mainHolder.addView(card, params);
this.mainHolder.setGravity(RelativeLayout.END_OF);
card.setOnTouchListener(new MyTouchListener());
}
Main holder layout:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clipChildren="false"
android:padding="4dp" />