Monday, February 21, 2011

Adding LayoutParams

Adding the LayoutParams to the control


LinearLayout.LayoutParams params=new LinearLayout.LayoutParams(
            LayoutParams.FILL_PARENT,
            LayoutParams.WRAP_CONTENT);
    params.leftMargin=22;
params.height=20;
params.width=10;

Creating dynamic controls.

Here is the code for dynamically creating controls in the table layout...
TableLayout tl=(TableLayout)findViewById(R.id.NewsTable);
 for (int i = 0; i < 16; i++)
 {
TableRow tr=new TableRow(this);
TextView TV=new TextView(this);
 TV.setText("Dynamic Button--"+i);
ImageView IV=new ImageView(this);
 Uri imgUri=Uri.parse("android.resource://com.example.hello/"+R.drawable.icon);
IV.setImageURI(imgUri);
 tr.addView(IV);
 tr.addView(TV);
tl.addView(tr);