Professional Documents
Culture Documents
Package Import Import Import Import Import Import Import Import Public Class Extends
Package Import Import Import Import Import Import Import Import Public Class Extends
Package Import Import Import Import Import Import Import Import Public Class Extends
myapplication;
import androidx.appcompat.app.AppCompatActivity;
import android.graphics.Color;
import android.graphics.Point;
import android.os.Bundle;
import android.view.Display;
import android.view.Gravity;
import android.widget.Button;
import android.widget.LinearLayout;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Display d=getWindowManager().getDefaultDisplay();
Point s=new Point();
d.getSize(s);
int w=s.x;
int h=s.y;
Button b=new Button(this);
b.setText("Go");
b.setBackgroundColor(Color.GREEN);
LinearLayout l = new LinearLayout(this);
l.setBackgroundColor(Color.CYAN);
l.setVerticalGravity(Gravity.CENTER);
LinearLayout.LayoutParams bp=new LinearLayout.LayoutParams( w/3 ,
LinearLayout.LayoutParams.WRAP_CONTENT);
l.addView(b,bp);
setContentView(l);
}
}