while(ScreenUtil.px2dip(itemView.getWidth())<ScreenUtil.px2dip(mTagContainer.getWidth())+24){ ConstraintLayout.LayoutParams lp = (ConstraintLayout.LayoutParams) mTagContainer.getLayoutParams(); lp.width = ScreenUtil.dip2px(ScreenUtil.px2dip(mTagContainer.getWidth())-80); } The reason this is 80 is because each small tag and its marginleft value add up to 80 <ConstraintLayout <LinearLayout Android :id="@+id/tag_container" android:layout_width="380dp" android:layout_height="wrap_content" android:layout_marginLeft="12dp" android:layout_marginTop="20dp" android:orientation="horizontal" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintTop_toBottomOf="@+id/first_line"> <ImageView android:id="@+id/billions_logo" android:layout_width="56dp" android:layout_height="18dp" android:layout_marginRight="4dp"/> <android.support.v7.widget.RecyclerView android:id="@+id/rv_tags" android:layout_width="wrap_content" android:layout_height="match_parent" /> </LinearLayout> </ConstraintLayout> <LinearLayout android:orientation="horizontal" xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content"> <ImageView android:layout_marginLeft="8dp" android:layout_width="72dp" android:layout_height="18dp" android:id="@+id/tv_tag_image" /> </LinearLayout>Copy the code