<LinearLayout
android:id="@+id/layout_handy_house_detail"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_gravity="center"
android:gravity="center"
android:layout_margin="20dp">
</LinearLayout>
for(int i = 0; i < 4; i++) {
final TextView textView = new TextView(this);
Drawable drawable = getResources().getDrawable(R.drawable.house_detail_shape);
textView.setText("Text "+i);
textView.setTextColor(0xff2588D4);
textView.setBackground(drawable);
textView.setPadding(30,8,30,8);
int curTextViewId = prevTextViewId + 1;
textView.setId(curTextViewId);
final LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
params.setMargins(0,0,20,0);
textView.setLayoutParams(params);
prevTextViewId = curTextViewId;
layout.addView(textView, params);
}