Using LinearLayout.LayoutParams : LinearLayout « UI « Android






Using LinearLayout.LayoutParams

   


package app.test;

import android.app.Activity;
import android.os.Bundle;
import android.view.ViewGroup.LayoutParams;
import android.widget.LinearLayout;
import android.widget.TextView;

public class Test extends Activity {
  TextView myTextView;
  private static boolean inflate = true;

  @Override
  public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    if (inflate)
      inflateXMLLayout();
    else
      constructLayout();
  }

  private void inflateXMLLayout() {
    setContentView(R.layout.main);
    myTextView = (TextView) findViewById(R.id.myTextView);
  }

  private void constructLayout() {
    LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
        LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
    LinearLayout.LayoutParams textViewLP = new LinearLayout.LayoutParams(
        LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
    LinearLayout ll = new LinearLayout(this);
    ll.setOrientation(LinearLayout.VERTICAL);
    myTextView = new TextView(this);
    myTextView.setText("Hello World, HelloWorld");
    ll.addView(myTextView, textViewLP);
    addContentView(ll, lp);
  }
}

//main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="vertical"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  >
  <TextView  
    android:id="@+id/myTextView"
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="Hello World, HelloWorld"
  />
</LinearLayout>

   
    
    
  








Related examples in the same category

1.Adding two controls to LinearLayout
2.Using LinearLayout for Activity
3.Using LinearLayout to layout two RadioGroups
4.LinearLayout for ListAdapter
5.Using LinearLayout
6.LinearLayout which uses a combination of wrap_content on itself and match_parent on its children to get every item to be the same width.
7.LinearLayout inside ScrollView
8.Transparent Panel extends LinearLayout
9.Set min height
10.Set padding right
11.Set padding with dpi value
12.Baseline alignment includes a android.widget.LinearLayout within another android.widget.LinearLayout.