How to layout @ java

To layout @ xml is ....., not to discuss any more.


Today, to list how to layout @ java.

1. to define an layout to LinearLayout or TableLayout, and to set its orient.
LinearLayout layout = new LinearLayout(this);
        layout.setOrientation(LinearLayout.VERTICAL);


2. to defines some View and its attribute.
TextView tv = new TextView(this);
        tv.setText("Hello Android!");
        tv.setGravity(1);
LinearLayout.LayoutParams param =
            new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);


3. to add it into layout.
layout.addView(tv,param);


That's all!

你可能感兴趣的:(java,xml,android)