Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Add Dynamic Layout in Android

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 390
    Comment on it

    Generally we add layout from xml but sometimes we need to add layout using java. Here I am adding linear layout from java file. I am creating LinearLayout class which is provided by Android and add params on it. We have methods to set orientation, gravity etc.

    public class DynamicLayoutActivity extends Activity { 
        LinearLayout dynamicLinearLayout; 
        TextView text; 
        @Override 
        protected void onCreate(Bundle savedInstanceState) { 
            super.onCreate(savedInstanceState); 
            dynamicLinearLayout = new LinearLayout(this); 
            dynamicLinearLayout.setOrientation(LinearLayout.VERTICAL); 
            LayoutParams layoutParam = new LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 
    LinearLayout.LayoutParams.MATCH_PARENT); 
            dynamicLinearLayout.setLayoutTexts(text); 
            text = new TextView(this); 
            text.setLayoutTexts(new LayoutTexts(LinearLayout.LayoutTexts.MATCH_PARENT, 
    LinearLayout.LayoutTexts.WRAP_CONTENT)); 
            text.setText("Dynamic Layout.. Yesssss."); 
            text.setGravity(Gravity.CENTER); 
            dynamicLinearLayout.addView(text); 
           setContentView(dynamicLinearLayout); 
        } 
      }

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: