Hi,
I am creating a TextView dynamically from Activity. I created 2 Textviews and I want to maintain some gap between 2 TextViews. How can this be achieved through code rather than from XML. Normally in XML we use android:layout_marginLeft/Right tag to maintain gap between 2 TextViews. How can this be achieved through code?
Thanks in Advance,
views:
113answers:
1
A:
It depends on the layout you are using. This example places a RelativeLayout in a LinearLayout
LinearLayout linearLayoutParent;
RelativeLayout relativeLayout;
RelativeLayout.LayoutParams margin = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.FILL_PARENT,
RelativeLayout.LayoutParams.WRAP_CONTENT);
margin.setMargins(0, 0, 0, 7); //7px bottom margin
//get or create the linear and the relative layouts
...
// Add view with its margins
linearLayoutParent.addView(relativeLayout, margin);
Maragues
2010-10-11 10:43:15
Thank you, ur suggestion worked for me.
Android_programmer_camera
2010-10-11 11:01:56