본문 바로가기

Android

레이아웃 파라미터(layoutparmeter)

package com.example.testex13;

 

import android.os.Bundle;

 

import android.app.Activity;

import android.graphics.Color;

import android.view.Gravity;

import android.view.Menu;

import android.view.TextureView;

import android.widget.LinearLayout;

import android.widget.TextView;

 

public class MainActivity extends Activity {

 

    @Override

    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        LinearLayout linear = new LinearLayout(this);

        linear.setOrientation(LinearLayout.VERTICAL);

        linear.setGravity(Gravity.CENTER);

        linear.setBackgroundColor(Color.LTGRAY);

       

        TextView text = new TextView(this);

        text.setText("TextView");

        text.setTextColor(Color.RED);

        text.setTextSize(20);

        text.setBackgroundColor(Color.GREEN);

       

        LinearLayout.LayoutParams paramtext = new LinearLayout.LayoutParams(

                 LinearLayout.LayoutParams.WRAP_CONTENT,

                 LinearLayout.LayoutParams.WRAP_CONTENT);

        linear.addView(text, paramtext);

           

        setContentView(linear);

    }

 

 

    @Override

    public boolean onCreateOptionsMenu(Menu menu) {

        // Inflate the menu; this adds items to the action bar if it is present.

        getMenuInflater().inflate(R.menu.main, menu);

        return true;

    }

   

}