Back to project page introToDroid4ed.
The source code is released under:
GNU General Public License
If you think the Android project introToDroid4ed listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.introtoandroid.samelayout; /*w ww . j a v a 2 s . c o m*/ import android.os.Bundle; import android.util.TypedValue; import android.widget.LinearLayout; import android.widget.TextView; public class ProgrammaticLayoutActivity extends MenuActivity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); TextView text1 = new TextView(this); text1.setText(R.string.string1); TextView text2 = new TextView(this); text2.setText(R.string.string2); text2.setTextSize(TypedValue.COMPLEX_UNIT_SP, 60); /* * Convert DP to PX * Our DP padding setting from our dimen resource * is in DP but setPadding requires pixels */ int pixelDimen = (int) TypedValue.applyDimension( TypedValue.COMPLEX_UNIT_DIP, 16, getResources().getDisplayMetrics()); LinearLayout ll = new LinearLayout(this); ll.setOrientation(LinearLayout.VERTICAL); ll.setPadding(pixelDimen, pixelDimen, pixelDimen, pixelDimen); ll.addView(text1); ll.addView(text2); setContentView(ll); } }