tags:

views:

436

answers:

1

I need to create a GUI (layout+views) in my .java activity class (I know it's far more flexible and easier to use .xml layout file, but I don't want to use it for now).

I can't find any setGravity() (but a "Gravity" object I can't figure how to use) or any set setMargin() method for the "View" object.

What is the easiest way to do it ?

Thanx.

A: 

You can add gravity to the "layouts" not to the "controls". Try to set gravity to any of your Linear/Relative or Frame layouts using setGravity(); .

Eg:

LinearLayout lll = (LinearLayout) findViewById(R.id.layoutname);
        lll.setGravity(Gravity.CENTER);
Vishwanath