package com.example.andy.myapplication;

import android.os.Bundle;
import android.support.constraint.ConstraintLayout;
import android.support.v7.app.AppCompatActivity;
import android.view.Gravity;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {
    ConstraintLayout constraintLayout;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        TextView msg = new TextView(this);
        msg.setText("sample text for checking diemnsions");
        msg.setPadding(10, 10, 10, 10);
        msg.measure(0, 0);
        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
        params.setMargins(5, 15, 0, 0);
        msg.setLayoutParams(params);
        msg.setGravity(Gravity.CENTER);
        LinearLayout chat = (LinearLayout) findViewById(R.id.rootview);
        chat.addView(msg);
        int width = msg.getMeasuredHeight();
        int height = msg.getMeasuredWidth();
        Toast.makeText(this, "width " + String.valueOf(width) + " height " + String.valueOf(height), Toast.LENGTH_LONG).show();

    }

}

